mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
Fix bug where popular tags cache applies to all limits
This commit is contained in:
parent
6113eb2d48
commit
8875d75a9f
1 changed files with 4 additions and 3 deletions
|
@ -23,11 +23,12 @@ class Tag < Sequel::Model
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.popular_names(limit=10)
|
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?
|
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
|
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.set cache_key, res.to_msgpack
|
||||||
$redis_cache.expire :tag_popular_names, 86400 # 24 hours
|
$redis_cache.expire cache_key, 86400 # 24 hours
|
||||||
else
|
else
|
||||||
res = MessagePack.unpack cache, symbolize_keys: true
|
res = MessagePack.unpack cache, symbolize_keys: true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue