diff options
author | rhenium <rhenium@rhe.jp> | 2014-10-11 07:22:28 +0900 |
---|---|---|
committer | rhenium <rhenium@rhe.jp> | 2014-10-11 07:22:28 +0900 |
commit | 27c820e260aa42273d1dbaf8a0a803a4c9e87743 (patch) | |
tree | 62e507313615084c2035f74df4bba6a1a7e1e988 | |
parent | 4751d3adee9a73a49a47b87b6bc27634342d0a48 (diff) | |
download | aclog-27c820e260aa42273d1dbaf8a0a803a4c9e87743.tar.gz |
cleanup
-rw-r--r-- | app/controllers/tweets_controller.rb | 18 | ||||
-rw-r--r-- | app/models/account.rb | 2 | ||||
-rw-r--r-- | app/models/tweet.rb | 6 | ||||
-rw-r--r-- | app/models/worker_manager.rb | 1 |
4 files changed, 9 insertions, 18 deletions
diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index 789b218..cfe96cd 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -1,13 +1,10 @@ class TweetsController < ApplicationController - after_action :eager_load_user - def show @tweet = Tweet.find(params[:id]) - rescue - import - else @user = @tweet.user authorize_to_show_user! @user + rescue ActiveRecord::RecordNotFound + import end def import @@ -21,7 +18,7 @@ class TweetsController < ApplicationController account = nil end - tweet = Tweet.import_from_twitter(params[:id], account ? account.client : nil) + tweet = Tweet.import_from_twitter(params[:id], account) redirect_to tweet end @@ -74,10 +71,7 @@ class TweetsController < ApplicationController end def filter - @tweets = paginate Tweet.recent(7.days).filter_by_query(params[:q].to_s).order_by_id.eager_load(:user) - if params[:registered] - @tweets = @tweets.to_a.select {|t| t.user.registered? } - end + @tweets = paginate Tweet.recent((params[:period] || 7).days).filter_by_query(params[:q].to_s).order_by_id end # /i/:id/{favorites,retweets}.json @@ -109,13 +103,11 @@ class TweetsController < ApplicationController [(params[:count] || Settings.tweets.count.default).to_i, Settings.tweets.count.max].min end - def eager_load_user + def render(*args) if @tweets && @tweets.is_a?(ActiveRecord::Relation) @tweets = @tweets.eager_load(:user) end - end - def render(*args) if @tweets && @tweets.length > 0 if @page @prev_url = @page == 1 ? nil : url_for(params.merge(page: @page - 1)) diff --git a/app/models/account.rb b/app/models/account.rb index b7cd690..d4486b9 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,5 +1,3 @@ -require "msgpack/rpc/transport/unix" - class Account < ActiveRecord::Base enum status: { active: 0, inactive: 1, revoked: 2 } diff --git a/app/models/tweet.rb b/app/models/tweet.rb index c14dbda..009f868 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -60,10 +60,10 @@ class Tweet < ActiveRecord::Base # Imports a Tweet from Twitter REST API. # If the client is not specified, An random account will be selected from database. # @param [Integer] id Target status ID. - # @param [Twitter::REST::Client] client The Twitter::REST::Client to be used. + # @param [Account] client The Twitter::REST::Client to be used. # @return [Tweet] The Tweet instance imported. - def import_from_twitter(id, client = nil) - client ||= Account.random.client + def import_from_twitter(id, account = nil) + client = (account || Account.random).client st = client.status(id) self.create_bulk_from_json([st.attrs]) diff --git a/app/models/worker_manager.rb b/app/models/worker_manager.rb index 9366f56..4c0fd7b 100644 --- a/app/models/worker_manager.rb +++ b/app/models/worker_manager.rb @@ -1,4 +1,5 @@ require "msgpack/rpc/transport/unix" + class WorkerManager class << self def alive? |