From c0c559f1c4fb230b18308e6c872c57fb84ce2f44 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 29 Jul 2021 13:18:21 -0700 Subject: [PATCH 1/5] skip some heavy cachebuilding for doc update api calls --- app/controllers/documents_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 4ded2037..11409780 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -10,6 +10,10 @@ class DocumentsController < ApplicationController before_action :set_navbar_actions, except: [:edit, :plaintext] before_action :set_footer_visibility, only: [:edit] + # Skip UI-heavy calls for API endpoints + skip_before_action :cache_most_used_page_information, only: [:update] + skip_before_action :cache_forums_unread_counts, only: [:update] + # TODO: verify_user_can_read, verify_user_can_edit, etc before_actions instead of inlining them before_action :cache_linkable_content_for_each_content_type, only: [:edit] From 78bfb55d67a6670fb8b755d9abd5c0b2950ea323 Mon Sep 17 00:00:00 2001 From: drusepth Date: Thu, 30 Sep 2021 16:44:16 -0700 Subject: [PATCH 2/5] cache linkable image lookups --- app/models/concerns/has_image_uploads.rb | 9 ++++++++- app/views/main/dashboard.html.erb | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/has_image_uploads.rb b/app/models/concerns/has_image_uploads.rb index a59df6d2..28b36c52 100644 --- a/app/models/concerns/has_image_uploads.rb +++ b/app/models/concerns/has_image_uploads.rb @@ -17,7 +17,14 @@ module HasImageUploads end def random_image_including_private(format: :medium) - image_uploads.sample.try(:src, format).presence || "card-headers/#{self.class.name.downcase.pluralize}.jpg" + @cache ||= {} + key = self.class.name + self.id.to_s + return @cache[key] if @cache.key?(key) + + result = image_uploads.sample.try(:src, format).presence || "card-headers/#{self.class.name.downcase.pluralize}.jpg" + @cache[key] = result + + result end def first_public_image(format: :medium) diff --git a/app/views/main/dashboard.html.erb b/app/views/main/dashboard.html.erb index b6b52bcc..fc9642b8 100644 --- a/app/views/main/dashboard.html.erb +++ b/app/views/main/dashboard.html.erb @@ -184,8 +184,10 @@ <% end %>
Create something new
+ <% shown_creatures = false %> <% @activated_content_types.sample(3).each do |type| %> <% klass = content_class_from_name(type) %> + <% shown_creatures = true if type == 'Creature' %>
<%= link_to send("new_#{type.downcase}_path"), class: "white-text", style: 'width: 100%' do %>
From 055cdd17b010c1650eb3a7ef6396f986627077b4 Mon Sep 17 00:00:00 2001 From: drusepth Date: Thu, 30 Sep 2021 16:44:31 -0700 Subject: [PATCH 3/5] show free-creatures banner --- app/views/main/dashboard.html.erb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/views/main/dashboard.html.erb b/app/views/main/dashboard.html.erb index fc9642b8..73c5de64 100644 --- a/app/views/main/dashboard.html.erb +++ b/app/views/main/dashboard.html.erb @@ -209,6 +209,24 @@ <% end %>
<% end %> + +
+
+ <%= link_to new_creature_path, class: "white-text", style: 'width: 100%' do %> +
+
+ <%= Creature.icon %> + + New Creature
+ + Free for all users in October + +
+
+
+ <% end %> +
+
From 3326b9affb623ef503fdae6920043f3a15c106aa Mon Sep 17 00:00:00 2001 From: drusepth Date: Thu, 30 Sep 2021 16:56:26 -0700 Subject: [PATCH 4/5] make creatures free in october --- app/models/page_types/creature.rb | 2 +- config/initializers/content_types.rb | 2 +- config/initializers/promos.rb | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/page_types/creature.rb b/app/models/page_types/creature.rb index 61925486..19ad5da3 100644 --- a/app/models/page_types/creature.rb +++ b/app/models/page_types/creature.rb @@ -20,7 +20,7 @@ class Creature < ApplicationRecord include Serendipitous::Concern include Authority::Abilities - self.authorizer_name = 'ExtendedContentAuthorizer' + self.authorizer_name = 'CoreContentAuthorizer' # Locations relates :habitats, with: :wildlifeships diff --git a/config/initializers/content_types.rb b/config/initializers/content_types.rb index 2644df09..30998968 100644 --- a/config/initializers/content_types.rb +++ b/config/initializers/content_types.rb @@ -66,7 +66,7 @@ Rails.application.config.content_types = { # Content types to label as "new" around the site new: [ - Lore + ] } diff --git a/config/initializers/promos.rb b/config/initializers/promos.rb index e58bd393..560d1547 100644 --- a/config/initializers/promos.rb +++ b/config/initializers/promos.rb @@ -6,7 +6,7 @@ Rails.application.config.promos[:promo_bogo] = {} Rails.application.config.promos[:promo_bogo][:start_date] = 'March 21, 2020'.to_date Rails.application.config.promos[:promo_bogo][:end_date] = Rails.application.config.promos[:promo_bogo][:start_date] + 2.weeks -# Lore free during the month of April +# Lore free during the month of April, 2020 # Need to change Lore.rb authorizer at the end lol if Date.current >= 'March 1, 2020'.to_date if Date.current < 'April 1, 2020'.to_date @@ -14,3 +14,12 @@ if Date.current >= 'March 1, 2020'.to_date Rails.application.config.content_types[:premium] -= [Lore] end end + +# Lore free during the month of October +# Need to change Creature.rb authorizer at the end +if Date.current >= 'October 1, 2021'.to_date + if Date.current < 'November 1, 2021'.to_date + Rails.application.config.content_types[:free] << Creature + Rails.application.config.content_types[:premium] -= [Creature] + end +end From 255a4979f7b579fb120acb1f0aa388aa222650fb Mon Sep 17 00:00:00 2001 From: drusepth Date: Thu, 30 Sep 2021 17:00:12 -0700 Subject: [PATCH 5/5] Safer cache name --- app/models/concerns/has_image_uploads.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/has_image_uploads.rb b/app/models/concerns/has_image_uploads.rb index 28b36c52..9327744a 100644 --- a/app/models/concerns/has_image_uploads.rb +++ b/app/models/concerns/has_image_uploads.rb @@ -17,12 +17,12 @@ module HasImageUploads end def random_image_including_private(format: :medium) - @cache ||= {} + @random_image_including_private_cache ||= {} key = self.class.name + self.id.to_s - return @cache[key] if @cache.key?(key) + return @random_image_including_private_cache[key] if @random_image_including_private_cache.key?(key) result = image_uploads.sample.try(:src, format).presence || "card-headers/#{self.class.name.downcase.pluralize}.jpg" - @cache[key] = result + @random_image_including_private_cache[key] = result result end