From 8875d75a9fce2d911a1210fcfbd9de966b0468c8 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 9 Oct 2019 14:09:11 -0700 Subject: [PATCH] Fix bug where popular tags cache applies to all limits --- models/tag.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/models/tag.rb b/models/tag.rb index e1844e28..76a1e611 100644 --- a/models/tag.rb +++ b/models/tag.rb @@ -23,11 +23,12 @@ class Tag < Sequel::Model end def self.popular_names(limit=10) - cache = $redis_cache['tag_popular_names'] + cache_key = "tag_popular_names_#{limit}".to_sym + cache = $redis_cache[cache_key] if cache.nil? res = DB["select tags.name,count(*) as c from sites_tags inner join tags on tags.id=sites_tags.tag_id where tags.name != '' and tags.is_nsfw='f' group by tags.name having count(*) > 1 order by c desc LIMIT ?", limit].all - $redis_cache.set :tag_popular_names, res.to_msgpack - $redis_cache.expire :tag_popular_names, 86400 # 24 hours + $redis_cache.set cache_key, res.to_msgpack + $redis_cache.expire cache_key, 86400 # 24 hours else res = MessagePack.unpack cache, symbolize_keys: true end