diff options
author | re4k <re4k@re4k.info> | 2013-06-15 17:31:51 +0900 |
---|---|---|
committer | re4k <re4k@re4k.info> | 2013-06-15 17:31:51 +0900 |
commit | 1caa370000cebdf39b5d627250d480fdee6949b0 (patch) | |
tree | e7a2d88863af1b4964343c2d73f9945fc25435f3 | |
parent | a74049a4bb0a8097763efd44ed8182a38727603f (diff) | |
download | aclog-1caa370000cebdf39b5d627250d480fdee6949b0.tar.gz |
fix Tweet.cache_list
-rw-r--r-- | app/models/tweet.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 46c3389..0b24c59 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -1,3 +1,5 @@ +require "digest/md5" + class Tweet < ActiveRecord::Base extend Aclog::Twitter @@ -150,13 +152,13 @@ class Tweet < ActiveRecord::Base end def self.cache_list(expires_in) - key = "tweets/#{scoped.to_sql}" + key = "tweets/ids/#{Digest::MD5.hexdigest(scoped.to_sql)}" ids = Rails.cache.read(key) unless ids - ids = pluck(:id) + ids = scoped.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") + unscoped.where(id: ids).order("CASE tweets.id #{ids.each_with_index.map {|m, i| "WHEN #{m} THEN #{i}" }.join(" ")} END") end end |