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