Add tag_colors cache to redis (#4716) [deploy]

This commit is contained in:
jeffin sam 2019-11-13 21:13:22 +05:30 committed by Molly Struve
parent 57250ade63
commit 61788e5dec
3 changed files with 5 additions and 3 deletions

View file

@ -111,7 +111,7 @@ module ApplicationHelper
end
def tag_colors(tag)
Rails.cache.fetch("view-helper-#{tag}/tag_colors", expires_in: 5.hours) do
RedisRailsCache.fetch("view-helper-#{tag}/tag_colors", expires_in: 5.hours) do
if (found_tag = Tag.select(%i[bg_color_hex text_color_hex]).find_by(name: tag))
{ background: found_tag.bg_color_hex, color: found_tag.text_color_hex }
else

View file

@ -173,7 +173,8 @@
<% cache("main-article-tags-#{@article.cached_tag_list}", expires_in: 30.hours) do %>
<div class="tags">
<% @article.cached_tag_list_array.each do |tag| %>
<a class="tag" href="/t/<%= tag %>" style="background-color:<%= tag_colors(tag)[:background] %>;color:<%= tag_colors(tag)[:color] %>">#<%= tag %></a>
<% tag_hash = tag_colors(tag) %>
<a class="tag" href="/t/<%= tag %>" style="background-color:<%= tag_hash[:background] %>;color:<%= tag_hash[:color] %>">#<%= tag %></a>
<% end %>
</div>
<% end %>

View file

@ -103,7 +103,8 @@
<% cache("main-article-tags-#{article.cached_tag_list}", expires_in: 30.hours) do %>
<div class="tags">
<% article.cached_tag_list_array.each do |tag| %>
<a class="tag" href="/t/<%= tag %>" style="background-color:<%= tag_colors(tag)[:background] %>;color:<%= tag_colors(tag)[:color] %>">#<%= tag %></a>
<% tag_hash = tag_colors(tag) %>
<a class="tag" href="/t/<%= tag %>" style="background-color:<%= tag_hash[:background] %>;color:<%= tag_hash[:color] %>">#<%= tag %></a>
<% end %>
</div>
<% end %>