Fix bug where popular tags cache applies to all limits

This commit is contained in:
Kyle Drake 2019-10-09 14:09:11 -07:00
parent 6113eb2d48
commit 8875d75a9f

View file

@ -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