aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/tweets_controller.rb26
-rw-r--r--app/models/account.rb11
-rw-r--r--app/models/tweet.rb2
-rw-r--r--app/models/user.rb7
-rw-r--r--app/models/worker_manager.rb2
-rw-r--r--app/views/about/index.html.haml2
-rw-r--r--app/views/apidocs/index.html.haml2
-rw-r--r--app/views/settings/deactivate.html.haml1
8 files changed, 27 insertions, 26 deletions
diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb
index ac51569..2308bb0 100644
--- a/app/controllers/tweets_controller.rb
+++ b/app/controllers/tweets_controller.rb
@@ -1,4 +1,6 @@
class TweetsController < ApplicationController
+ after_action :eager_load_user
+
def show
@tweet = Tweet.find(params[:id])
@user = @tweet.user
@@ -39,26 +41,26 @@ class TweetsController < ApplicationController
@user = require_user
authorize_to_show_user! @user
authorize_to_show_user_best! @user
- @tweets = paginate_with_page_number @user.tweets.reacted.order_by_reactions.eager_load_for_html
+ @tweets = paginate_with_page_number @user.tweets.reacted.order_by_reactions
end
def user_recent
@user = require_user
authorize_to_show_user! @user
authorize_to_show_user_best! @user
- @tweets = paginate_with_page_number @user.tweets.reacted.recent.order_by_reactions.eager_load_for_html
+ @tweets = paginate_with_page_number @user.tweets.reacted.recent.order_by_reactions
end
def user_timeline
@user = require_user
authorize_to_show_user! @user
- @tweets = paginate @user.tweets.reacted(params[:reactions]).order_by_id.eager_load_for_html
+ @tweets = paginate @user.tweets.reacted(params[:reactions]).order_by_id
end
def user_favorites
@user = require_user
authorize_to_show_user! @user
- @tweets = paginate_with_page_number Tweet.reacted(params[:reactions]).favorited_by(@user).order("`favorites`.`id` DESC").eager_load_for_html
+ @tweets = paginate_with_page_number Tweet.reacted(params[:reactions]).favorited_by(@user).order("`favorites`.`id` DESC")
end
def user_favorited_by
@@ -66,23 +68,23 @@ class TweetsController < ApplicationController
authorize_to_show_user! @user
@source_user = User.find(id: params[:source_user_id], screen_name: params[:source_screen_name])
authorize_to_show_user! @source_user
- @tweets = paginate @user.tweets.reacted(params[:reactions]).favorited_by(@source_user).order_by_id.eager_load_for_html
+ @tweets = paginate @user.tweets.reacted(params[:reactions]).favorited_by(@source_user).order_by_id
end
def all_best
- @tweets = paginate_with_page_number Tweet.reacted.order_by_reactions.eager_load_for_html
+ @tweets = paginate_with_page_number Tweet.reacted.order_by_reactions
end
def all_recent
- @tweets = paginate_with_page_number Tweet.recent.reacted.order_by_reactions.eager_load_for_html
+ @tweets = paginate_with_page_number Tweet.recent.reacted.order_by_reactions
end
def all_timeline
- @tweets = paginate Tweet.reacted(params[:reactions]).order_by_id.eager_load_for_html
+ @tweets = paginate Tweet.reacted(params[:reactions]).order_by_id
end
def filter
- @tweets = paginate Tweet.recent(7.days).filter_by_query(params[:q].to_s).order_by_id.eager_load_for_html
+ @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
@@ -110,6 +112,12 @@ class TweetsController < ApplicationController
[(params[:count] || Settings.tweets.count.default).to_i, Settings.tweets.count.max].min
end
+ def eager_load_user
+ if @tweets && @tweets.is_a?(ActiveRecord::Relation)
+ @tweets = @tweets.eager_load(:user)
+ end
+ end
+
def render(*args)
if @tweets && @tweets.length > 0
if @page
diff --git a/app/models/account.rb b/app/models/account.rb
index f515768..e71d0f1 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -30,20 +30,21 @@ class Account < ActiveRecord::Base
end
def client
- @client ||= Twitter::REST::Client.new(consumer_key: Settings.consumer.key,
- consumer_secret: Settings.consumer.secret,
- access_token: oauth_token,
- access_token_secret: oauth_token_secret)
+ @_client ||= Twitter::REST::Client.new(consumer_key: Settings.consumer.key,
+ consumer_secret: Settings.consumer.secret,
+ access_token: oauth_token,
+ access_token_secret: oauth_token_secret)
end
def following?(target_id)
+ target_id = target_id.id if target_id.is_a? User
friends.member? target_id
end
def friends
@_friends ||=
Rails.cache.fetch("accounts/#{self.id}/friends", expires_in: Settings.cache.friends) do
- Set.new self.client.friend_ids
+ Set.new client.friend_ids
end
end
end
diff --git a/app/models/tweet.rb b/app/models/tweet.rb
index 9f769d2..b5cf06e 100644
--- a/app/models/tweet.rb
+++ b/app/models/tweet.rb
@@ -10,8 +10,6 @@ class Tweet < ActiveRecord::Base
has_many :favoriters, -> { order("favorites.id") }, through: :favorites, source: :user
has_many :retweeters, -> { order("retweets.id") }, through: :retweets, source: :user
- scope :eager_load_for_html, -> { eager_load(:user) }
-
scope :recent, ->(period = 3.days) { where("tweets.id > ?", snowflake_min(Time.zone.now - period)) }
scope :reacted, ->(count = nil) { where("reactions_count >= ?", (count || 1).to_i) }
scope :not_protected, -> { joins(:user).references(:user).where(users: { protected: false }) }
diff --git a/app/models/user.rb b/app/models/user.rb
index 913a83d..6b584e4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -57,13 +57,8 @@ class User < ActiveRecord::Base
!registered? || registered? && account.private?
end
- def following?(user)
- raise Aclog::Exceptions::UserNotRegistered unless registered?
- account.following?(user.id)
- end
-
def permitted_to_see?(user)
- !user.protected? || user.id == self.id || self.following?(user) || false
+ !user.protected? || user.id == self.id || (self.registered? && account.following?(user))
end
def stats
diff --git a/app/models/worker_manager.rb b/app/models/worker_manager.rb
index 4cd9d52..9366f56 100644
--- a/app/models/worker_manager.rb
+++ b/app/models/worker_manager.rb
@@ -19,7 +19,7 @@ class WorkerManager
private
def client
- @client ||= begin
+ @_client ||= begin
transport = MessagePack::RPC::UNIXTransport.new
MessagePack::RPC::Client.new(transport, Rails.root.join("tmp", "sockets", "collector.sock").to_s)
rescue Errno::ECONNREFUSED, Errno::ENOENT
diff --git a/app/views/about/index.html.haml b/app/views/about/index.html.haml
index b5e0e3d..2d97b3b 100644
--- a/app/views/about/index.html.haml
+++ b/app/views/about/index.html.haml
@@ -31,7 +31,7 @@
.col-sm-6.col-sm-push-6<
%img{alt: "Protected account is OK", src: image_path("feature_3.png"), height: 200, width: 400}
.col-sm-6.col-sm-pull-6
- %h1 Protected User Available
+ %h1 For Protected Users
%p ツイートを非公開にしている方でもご利用いただけます。ツイートはあなたとあなたのフォロワーにしか見えないので安心です。
.front-feature-misc
.container
diff --git a/app/views/apidocs/index.html.haml b/app/views/apidocs/index.html.haml
index a440c55..1bfb197 100644
--- a/app/views/apidocs/index.html.haml
+++ b/app/views/apidocs/index.html.haml
@@ -15,7 +15,7 @@ OAuth Echo の詳細については
%h3= namespace.titleize
%table.table
%tbody
- - endpoints.select {|_, e| !e.route_nodoc }.each do |path, endpoint|
+ - endpoints.reject {|_, e| e.route_nodoc }.each do |path, endpoint|
%tr
%td= link_to format_endpoint_name(endpoint), about_api_endpoint_path(endpoint.route_method.downcase, namespace, path), class: (endpoint.route_deprecated ? "deprecated" : nil)
%td= endpoint.route_description
diff --git a/app/views/settings/deactivate.html.haml b/app/views/settings/deactivate.html.haml
index 709a7fc..f1ec1ed 100644
--- a/app/views/settings/deactivate.html.haml
+++ b/app/views/settings/deactivate.html.haml
@@ -1,4 +1,3 @@
- title "Account Deactivation"
%h1 Deactivation
ご利用ありがとうございました。記録を停止されますが、データは削除されません。もう一度ログインをすると記録が再開されます。
-