diff options
-rw-r--r-- | app/controllers/report_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 6 | ||||
-rw-r--r-- | app/models/account.rb | 6 | ||||
-rw-r--r-- | app/models/favorite.rb | 8 | ||||
-rw-r--r-- | app/models/retweet.rb | 8 | ||||
-rw-r--r-- | app/models/tweet.rb | 10 | ||||
-rw-r--r-- | app/models/user.rb | 29 | ||||
-rw-r--r-- | app/views/shared/user_ranking.html.haml | 2 | ||||
-rw-r--r-- | app/views/shared/user_ranking.json.jbuilder | 2 |
10 files changed, 11 insertions, 66 deletions
diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb index c522986..3070776 100644 --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -13,9 +13,9 @@ class ReportController < ApplicationController raise ActionController::BadRequest end - tweet = Tweet.cached(tweet_id) + tweet = Tweet.find(tweet_id) if tweet - original = Tweet.cached(original_id) + original = Tweet.find(original_id) unless original add_issue_stolen(false, tweet_id, original_id) return diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index d344312..1dfdfc5 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -22,7 +22,7 @@ class SearchController < ApplicationController key, value = word.split(":", 2) case key.downcase when /^-?user$/ - user = User.cached(value) + user = User.where(screen_name: value).first if key[0] == "-" tweets.where("user_id != ?", user ? user.id : -1) else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8f932b3..33c2539 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -189,11 +189,11 @@ class UsersController < ApplicationController end if params[:user_id] - user = User.cached(params[:user_id].to_i) + user = User.find(params[:user_id].to_i) end if !user && params[:screen_name] - user = User.cached(params[:screen_name]) + user = User.where(screen_name: params[:screen_name]).first end raise Aclog::Exceptions::UserNotFound unless user @@ -203,7 +203,7 @@ class UsersController < ApplicationController def include_user_b if params[:user_id_b] - user_b = User.cached(params[:user_id_b].to_i) + user_b = User.find(params[:user_id_b].to_i) end if !user_b && params[:screen_name_b] diff --git a/app/models/account.rb b/app/models/account.rb index 8a7fb9d..aed183d 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,4 +1,6 @@ class Account < ActiveRecord::Base + has_one :user + def self.create_or_update(hash) account = where(user_id: hash[:user_id]).first_or_initialize account.oauth_token = hash[:oauth_token] @@ -8,10 +10,6 @@ class Account < ActiveRecord::Base account end - def user - User.cached(user_id) - end - def client Twitter::Client.new( consumer_key: Settings.consumer[consumer_version.to_i].key, diff --git a/app/models/favorite.rb b/app/models/favorite.rb index 751c486..de274d5 100644 --- a/app/models/favorite.rb +++ b/app/models/favorite.rb @@ -7,14 +7,6 @@ class Favorite < ActiveRecord::Base order("id DESC") end - def user - User.cached(user_id) - end - - def tweet - Tweet.cached(tweet_id) - end - def self.from_hash(hash) begin f = create!(tweet_id: hash[:tweet_id], diff --git a/app/models/retweet.rb b/app/models/retweet.rb index 31a9e47..34b2646 100644 --- a/app/models/retweet.rb +++ b/app/models/retweet.rb @@ -7,14 +7,6 @@ class Retweet < ActiveRecord::Base order("id DESC") end - def user - User.cached(user_id) - end - - def tweet - Tweet.cached(tweet_id) - end - def self.from_hash(hash) begin r = create!(id: hash[:id], diff --git a/app/models/tweet.rb b/app/models/tweet.rb index b4beb43..9608fec 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -57,16 +57,6 @@ class Tweet < ActiveRecord::Base includes(:user).where(users: {protected: false}) end - def self.cached(id) - Rails.cache.fetch("tweet/#{id}", expires_in: 3.hour) do - where(id: id).first - end - end - - def user - User.cached(user_id) - end - def notify_favorite if [50, 100, 250, 500, 1000].include? favorites.count Aclog::Notification.reply_favs(self, favorites.count) diff --git a/app/models/user.rb b/app/models/user.rb index b56a5e6..56626a0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,31 +3,9 @@ class User < ActiveRecord::Base has_many :favorites, dependent: :delete_all has_many :retweets, dependent: :delete_all - def self.cached(identity) - if identity.is_a?(Fixnum) || identity.is_a?(Bignum) - Rails.cache.fetch("user/#{identity}", expires_in: 3.hour) do - where(id: identity).first - end - elsif identity.is_a?(String) - if /^[A-Za-z0-9_]{1,15}$/ =~ identity - uid = Rails.cache.fetch("screen_name/#{identity}", expires_in: 3.hour) do - if user = where(screen_name: identity).first - user.id - end - end - - cached(uid) - end - elsif identity.is_a?(NilClass) - nil - else - raise Exception, "Invalid identity: #{identity}" - end - end - def self.from_hash(hash) begin - user = cached(hash[:id]) || User.new(id: hash[:id]) + user = where(id: hash[:id]).first || User.new(id: hash[:id]) orig = user.attributes.dup user.screen_name = hash[:screen_name] @@ -57,11 +35,6 @@ class User < ActiveRecord::Base protected: user_object.protected) end - def self.delete_cache(uid) - Rails.cache.delete("user/#{uid}") - end - def delete_cache; User.delete_cache(id) end - def protected? protected end diff --git a/app/views/shared/user_ranking.html.haml b/app/views/shared/user_ranking.html.haml index c7e1a63..cc514ff 100644 --- a/app/views/shared/user_ranking.html.haml +++ b/app/views/shared/user_ranking.html.haml @@ -1,7 +1,7 @@ .users %ul.inline - @usermap.take(50).each do |user_id, count| - - user = User.cached(user_id) + - user = User.find(user_id) %li - if user .avatar diff --git a/app/views/shared/user_ranking.json.jbuilder b/app/views/shared/user_ranking.json.jbuilder index 8bbdd42..6888263 100644 --- a/app/views/shared/user_ranking.json.jbuilder +++ b/app/views/shared/user_ranking.json.jbuilder @@ -3,7 +3,7 @@ json.array! @usermap do |json, u| json.user do |json| json.id u[0] if @include_user - json.partial! "shared/partial/user", user: User.cached(u[0]) + json.partial! "shared/partial/user", user: User.find(u[0]) end end end |