Skip to content

Commit 1a59c4e

Browse files
authored
Merge pull request #1715 from codidact/0valt/pinned_link_cache_fix
NamespacedEnvCache fix + pinned links caching fix
2 parents ea496be + b121eeb commit 1a59c4e

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

app/models/pinned_link.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
class PinnedLink < ApplicationRecord
22
include MaybeCommunityRelated
33
belongs_to :post
4+
5+
# Is the link time-constrained?
6+
# @return [Boolean] check result
7+
def timed?
8+
shown_before.present? || shown_after.present?
9+
end
410
end

app/views/layouts/_sidebar.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
<% end %>
1313
<% end %>
1414

15-
1615
<% unless @community.is_fake %>
1716
<%# Featured widget %>
1817
<% if Rails.env.development? || @pinned_links.to_a.size > 0 %>
19-
<% cache @pinned_links do %>
18+
<% has_timed = @pinned_links.any?(&:timed?) %>
19+
<% cache_unless has_timed, @pinned_links do %>
2020
<div class="widget has-margin-4 is-teal">
2121
<% if Rails.env.development? || @pinned_links.to_a.size > 0 %>
2222
<div class="widget--header">Featured</div>
@@ -122,8 +122,8 @@
122122
<% if can_see_deleted_posts? && !at_least_moderator? %>
123123
<li><a href="/mod/deleted">Recent Deletions</a></li>
124124
<% end %>
125-
<%# this calls into application_helper, not the user model! %>
126-
<% if at_least_moderator? %>
125+
<%# this calls into application_helper, not the user model! %>
126+
<% if at_least_moderator? %>
127127
<li><%= link_to 'Moderator Tools', moderator_path %></li>
128128
<% end %>
129129
<% if admin? %>

config/environments/development.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
# Show full error reports and disable caching.
1616
config.consider_all_requests_local = true
17-
config.action_controller.perform_caching = false
17+
config.action_controller.perform_caching = ActiveRecord::Type::Boolean.new.cast(ENV['PERFORM_CACHING']) || false
1818

1919
# Enable server timing
2020
config.server_timing = true
2121

22+
config.log_level = ENV['LOG_LEVEL'] || :info
23+
2224
# Set the cache store to the redis that was configured in the database.yml
2325
processed = ERB.new(File.read(Rails.root.join('config', 'database.yml'))).result(binding)
2426
redis_config = YAML.safe_load(processed, permitted_classes: [], permitted_symbols: [], aliases: true)["redis_#{Rails.env}"]

lib/namespaced_env_cache.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def self.supports_cache_versioning?
8282
private
8383

8484
def construct_ns_key(key, include_community: true)
85+
key = expanded_key(key)
8586
c_id = RequestContext.community_id if include_community
8687
"#{Rails.env}://#{[c_id, key].compact.join('/')}"
8788
end

0 commit comments

Comments
 (0)