mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
quick and dirty cache for popular tags result
This commit is contained in:
parent
be6196d67c
commit
2f09415d88
4 changed files with 18 additions and 1 deletions
1
Gemfile
1
Gemfile
|
@ -38,6 +38,7 @@ gem 'will_paginate'
|
|||
gem 'simpleidn'
|
||||
gem 'gandi'
|
||||
gem 'hoe', '3.14.2', require: nil
|
||||
gem 'msgpack'
|
||||
|
||||
platform :mri, :rbx do
|
||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||
|
|
|
@ -101,6 +101,7 @@ GEM
|
|||
ruby-progressbar
|
||||
mocha (1.1.0)
|
||||
metaclass (~> 0.0.1)
|
||||
msgpack (0.7.5)
|
||||
multi_json (1.11.2)
|
||||
net-scp (1.2.1)
|
||||
net-ssh (>= 2.6.5)
|
||||
|
@ -259,6 +260,7 @@ DEPENDENCIES
|
|||
minitest
|
||||
minitest-reporters
|
||||
mocha
|
||||
msgpack
|
||||
paypal-recurring
|
||||
pg
|
||||
poltergeist
|
||||
|
@ -297,3 +299,6 @@ DEPENDENCIES
|
|||
webmock
|
||||
will_paginate
|
||||
zipruby
|
||||
|
||||
BUNDLED WITH
|
||||
1.11.2
|
||||
|
|
|
@ -62,6 +62,9 @@ Sidekiq.configure_client do |config|
|
|||
config.redis = sidekiq_redis_config
|
||||
end
|
||||
|
||||
$redis = Redis.new
|
||||
$redis_cache = Redis::Namespace.new :cache, redis: $redis
|
||||
|
||||
# :nocov:
|
||||
if ENV['RACK_ENV'] == 'development'
|
||||
# Run async jobs immediately in development.
|
||||
|
|
|
@ -23,6 +23,14 @@ class Tag < Sequel::Model
|
|||
end
|
||||
|
||||
def self.popular_names(limit=10)
|
||||
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
|
||||
cache = $redis_cache.get :tag_popular_names
|
||||
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
|
||||
else
|
||||
res = MessagePack.unpack cache, symbolize_keys: true
|
||||
end
|
||||
res
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue