Add new cache key for article sidebar & bottom_content (#12185)
* Add new cache key for article sidebar & bottom_content * Trigger build * Undo automatic changes from 'merge conflict fixes' commit * Revert to actual previous version, oops * Trying again... * Trying again... * Trying again... * Remove unnecessary variable Co-authored-by: Mac Siri <krairit.siri@gmail.com> Co-authored-by: Mac Siri <krairit.siri@gmail.com>
This commit is contained in:
parent
5b7a3df004
commit
8d462801ec
5 changed files with 20 additions and 3 deletions
|
|
@ -469,6 +469,7 @@ class Article < ApplicationRecord
|
|||
|
||||
def before_destroy_actions
|
||||
bust_cache
|
||||
touch_actor_latest_article_updated_at(destroying: true)
|
||||
article_ids = user.article_ids.dup
|
||||
if organization
|
||||
organization.touch(:last_article_at)
|
||||
|
|
@ -659,11 +660,19 @@ class Article < ApplicationRecord
|
|||
self.canonical_url = nil if canonical_url == ""
|
||||
end
|
||||
|
||||
def touch_actor_latest_article_updated_at(destroying: false)
|
||||
return unless destroying || saved_changes.keys.intersection(%w[title cached_tag_list]).present?
|
||||
|
||||
user.touch(:latest_article_updated_at)
|
||||
organization&.touch(:latest_article_updated_at)
|
||||
end
|
||||
|
||||
def bust_cache
|
||||
EdgeCache::Bust.call(path)
|
||||
EdgeCache::Bust.call("#{path}?i=i")
|
||||
EdgeCache::Bust.call("#{path}?preview=#{password}")
|
||||
async_bust
|
||||
touch_actor_latest_article_updated_at
|
||||
end
|
||||
|
||||
def calculate_base_scores
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
<% end %>
|
||||
</div>
|
||||
|
||||
<% cache("article-sticky-nav-articles-0-#{@article.id}-#{@actor.last_article_at}", expires_in: 48.hours) do %>
|
||||
<% cache("article-sticky-nav-articles-#{@article.id}-#{@actor.latest_article_updated_at}", expires_in: 48.hours) do %>
|
||||
<% if (user_stickies = Articles::GetUserStickies.call(@article, @actor)).present? %>
|
||||
<div class="crayons-card crayons-card--secondary">
|
||||
<header class="crayons-card__header">
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@
|
|||
|
||||
</article>
|
||||
|
||||
<% cache("article-bottom-content-#{@article.id}-#{user_signed_in?}", expires_in: 18.hours) do %>
|
||||
<% cache("article-bottom-content-#{@article.id}-#{user_signed_in?}-#{(@organization || @user).latest_article_updated_at}", expires_in: 18.hours) do %>
|
||||
<% suggested_articles = Articles::Suggest.call(@article, max: 4) %>
|
||||
<%= render "articles/bottom_content", articles: suggested_articles %>
|
||||
<% end %>
|
||||
|
|
@ -214,7 +214,7 @@
|
|||
</main>
|
||||
|
||||
<aside class="crayons-layout__sidebar-right" aria-label="Right sidebar navigation">
|
||||
<% stick_nav_cache_key = "sticky-sidebar-#{@article.id}-#{(@organization || @user).profile_updated_at}-#{(@organization || @user).last_article_at}-1-#{@user.pro?}" %>
|
||||
<% stick_nav_cache_key = "sticky-sidebar-#{@article.id}-#{(@organization || @user).profile_updated_at}-#{(@organization || @user).latest_article_updated_at}" %>
|
||||
<% cache(stick_nav_cache_key, expires_in: 50.hours) do %>
|
||||
<%= render "articles/sticky_nav" %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
class AddLatestArticleUpdatedAtToUsersAndOrgs < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :users, :latest_article_updated_at, :datetime
|
||||
add_column :organizations, :latest_article_updated_at, :datetime
|
||||
end
|
||||
end
|
||||
|
|
@ -800,6 +800,7 @@ ActiveRecord::Schema.define(version: 2021_01_11_151630) do
|
|||
t.integer "unspent_credits_count", default: 0, null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "url"
|
||||
t.datetime "latest_article_updated_at"
|
||||
t.index ["secret"], name: "index_organizations_on_secret", unique: true
|
||||
t.index ["slug"], name: "index_organizations_on_slug", unique: true
|
||||
end
|
||||
|
|
@ -1332,6 +1333,7 @@ ActiveRecord::Schema.define(version: 2021_01_11_151630) do
|
|||
t.boolean "welcome_notifications", default: true, null: false
|
||||
t.datetime "workshop_expiration"
|
||||
t.string "youtube_url"
|
||||
t.datetime "latest_article_updated_at"
|
||||
t.index ["apple_username"], name: "index_users_on_apple_username"
|
||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||
t.index ["created_at"], name: "index_users_on_created_at"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue