-
Notifications
You must be signed in to change notification settings - Fork 64
Cache related content #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2024-upgrades-main
Are you sure you want to change the base?
Conversation
Rails.cache.fetch("#{cache_key_with_version}/related_content") do | ||
RelatedContent.as_hash(related_content_url) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be good to let OpenURI::HTTPError
bubble up out of RelatedContent
and move the rescue to this method now, so that the {}
value doesn't get cached in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ended up addressing this by changing RelatedContent
to return nil
in all fail states & used the skip_nil
option on cache.fetch
to avoid caching nil
<h4>Related Content</h4> | ||
<%= link_to action_page.related_content_url do %> | ||
<div class="image"> | ||
<%= image_tag(action_page.related_content.image) %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The title/image methods in this view are called on a hash now so it needed some slight changes:
<h4>Related Content</h4>
<%= link_to action_page.related_content_url do %>
<div class="image">
- <%= image_tag(action_page.related_content.image) %>
+ <%= image_tag(action_page.related_content[:image_url]) %>
</div>
- <h5><%= action_page.related_content.title %></h5>
+ <h5><%= action_page.related_content[:title] %></h5>
<% end %>
</div>
<div class="desc-text">
@@ -14,8 +14,8 @@
<h4>Related Content</h4>
<%= link_to action_page.related_content_url do %>
<div class="image">
- <%= image_tag(action_page.related_content.image) %>
+ <%= image_tag(action_page.related_content[:image_url]) %>
</div>
- <h5><%= action_page.related_content.title %></h5>
+ <h5><%= action_page.related_content[:title] %></h5>
<% end %>
</div>
8a7e2c1
to
7ced577
Compare
The diff is quite large due to including all the files from a single deeplinks page as a test fixture -- this is not that big of a PR!
Cache related content on action pages. Currently this cache will become stale only when the action page is updated; we could add an expiry time instead if that's what we'd prefer or decide we need (I think blogposts that get attached to actions are usually not changing by the time they're added to an action, but that assumption could be wrong).