aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorre4k <re4k@re4k.info>2013-06-15 17:04:33 +0900
committerre4k <re4k@re4k.info>2013-06-15 17:04:33 +0900
commitf912b964a403f290bcb750ec9eb93eb87b355b77 (patch)
tree8986320e2d39fa377e6fba402724484e7c3f7880 /app
parentebe2afef9e998231d706d23af32c8e3c1eb08228 (diff)
downloadaclog-f912b964a403f290bcb750ec9eb93eb87b355b77.tar.gz
fix Tweet.cache_list
Diffstat (limited to 'app')
-rw-r--r--app/models/tweet.rb10
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