diff options
author | re4k <re4k@re4k.info> | 2013-06-15 17:04:33 +0900 |
---|---|---|
committer | re4k <re4k@re4k.info> | 2013-06-15 17:04:33 +0900 |
commit | f912b964a403f290bcb750ec9eb93eb87b355b77 (patch) | |
tree | 8986320e2d39fa377e6fba402724484e7c3f7880 /app | |
parent | ebe2afef9e998231d706d23af32c8e3c1eb08228 (diff) | |
download | aclog-f912b964a403f290bcb750ec9eb93eb87b355b77.tar.gz |
fix Tweet.cache_list
Diffstat (limited to 'app')
-rw-r--r-- | app/models/tweet.rb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 4b09171..2d55eda 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -152,13 +152,11 @@ class Tweet < ActiveRecord::Base def self.cache_list(expires_in) key = "tweets/#{scoped.to_sql}" ids = Rails.cache.read(key) - if ids - Tweet.where(id: ids).order("CASE #{ids.each_with_index.map {|m, i| "WHEN ID = #{m} THEN #{i}" }.join(" ")} END") - else - # use map instead of pluck: not to excecute new SQL - Rails.cache.write(key, scoped.map(&:id), expires_in: expires_in) - scoped + unless ids + ids = pluck(&:id) + Rails.cache.write(key, ids, expires_in: expires_in) end + Tweet.where(id: ids).order("CASE tweets.id #{ids.each_with_index.map {|m, i| "WHEN #{m} THEN #{i}" }.join(" ")} END") end end |