diff options
author | Rhenium <rhenium@rhe.jp> | 2013-07-29 05:32:08 +0900 |
---|---|---|
committer | Rhenium <rhenium@rhe.jp> | 2013-07-29 05:32:08 +0900 |
commit | a170af32edc5f18bb4260fb81ef6c5ea885a5610 (patch) | |
tree | 7421a462bbeadd2e9fe4d7c76ea6a91b73b67ea1 | |
parent | e2c42d9b4c4e5a5fd4a4b16744ff5973fc2d1095 (diff) | |
download | aclog-a170af32edc5f18bb4260fb81ef6c5ea885a5610.tar.gz |
deactivate
-rw-r--r-- | app/controllers/application_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 2 | ||||
-rw-r--r-- | app/models/account.rb | 10 | ||||
-rw-r--r-- | app/models/notification.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/shared/sidebar/_users.html.haml | 2 | ||||
-rw-r--r-- | app/views/users/stats.html.haml | 2 | ||||
-rw-r--r-- | collector/connection.rb | 7 | ||||
-rw-r--r-- | collector/stream.rb | 1 | ||||
-rw-r--r-- | lib/aclog/receiver/collector_connection.rb | 6 | ||||
-rw-r--r-- | lib/aclog/receiver/register_server.rb | 15 |
11 files changed, 29 insertions, 24 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4da5b86..4b78b9e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -41,7 +41,7 @@ class ApplicationController < ActionController::Base end def authorized_to_show_best?(user) - authorized_to_show_user?(user) && user.registered? && (!user.account.private? || user.id == session[:user_id]) + authorized_to_show_user?(user) && user.registered? && user.account.active? && (!user.account.private? || user.id == session[:user_id]) end def authorize_to_show_user!(user) @@ -50,7 +50,7 @@ class ApplicationController < ActionController::Base def authorize_to_show_best!(user) authorize_to_show_user!(user) - raise Aclog::Exceptions::UserNotRegistered.new(user) unless user.registered? + raise Aclog::Exceptions::UserNotRegistered.new(user) unless user.registered? && user.account.active? raise Aclog::Exceptions::AccountPrivate.new(user) if user.account.private? && user.id != session[:user_id] true end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 42ef707..31efbc0 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -3,7 +3,7 @@ class SearchController < ApplicationController def search @caption = "search" - @tweets = Tweet.parse_query(params[:query] || "").reacted.order_by_id.list(params, force_page: true) + @tweets = Tweet.parse_query(params[:query].to_s || "").reacted.order_by_id.list(params, force_page: true) @tweets = @tweets.recent(7) unless @tweets.to_sql.include?("`tweets`.`id`") end end diff --git a/app/models/account.rb b/app/models/account.rb index e43c145..a229f20 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,7 +1,7 @@ require "msgpack/rpc/transport/unix" class Account < ActiveRecord::Base - ACTIVE = 0; DEACTIVATED = 1 + ACTIVE = 0; INACTIVE = 1 belongs_to :user @@ -33,7 +33,7 @@ class Account < ActiveRecord::Base end def deactivate! - self.status = Account::DEACTIVATED + self.status = Account::INACTIVE self.save! if self.changed? update_connection @@ -42,11 +42,7 @@ class Account < ActiveRecord::Base def update_connection transport = MessagePack::RPC::UNIXTransport.new client = MessagePack::RPC::Client.new(transport, Rails.root.join("tmp", "sockets", "receiver.sock").to_s) - if self.status == Account::ACTIVE - client.call(:register, Marshal.dump(self)) - elsif self.status == Account::DEACTIVATED - client.call(:unregister, Marshal.dump(self)) - end + client.call(:register, Marshal.dump(self)) rescue Errno::ECONNREFUSED, Errno::ENOENT Rails.logger.error($!) end diff --git a/app/models/notification.rb b/app/models/notification.rb index f01393f..cc07f97 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,7 +1,7 @@ class Notification def self.notify_favorite(tweet) if Settings.notification.favorites.include?(tweet.favorites.count) - if tweet.user.registered? && tweet.user.account.notification? + if tweet.user.registered? && tweet.user.account.active? && tweet.user.account.notification? reply_favs(tweet, tweet.favorites.count) end end diff --git a/app/models/user.rb b/app/models/user.rb index 1c4cfb4..e072f94 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -54,7 +54,7 @@ class User < ActiveRecord::Base end def stats - raise Aclog::Exceptions::UserNotRegistered.new(self) unless registered? + raise Aclog::Exceptions::UserNotRegistered.new(self) unless registered? && account.active? Rails.cache.fetch("stats/#{self.id}", expires_in: 3.hours) do favorited_counts, retweeted_counts = self.tweets.pluck(:favorites_count, :retweets_count).transpose diff --git a/app/views/shared/sidebar/_users.html.haml b/app/views/shared/sidebar/_users.html.haml index 1b558b8..a5fdc00 100644 --- a/app/views/shared/sidebar/_users.html.haml +++ b/app/views/shared/sidebar/_users.html.haml @@ -3,7 +3,7 @@ = link_to user_path(@user.screen_name) do = image_tag @user.profile_image_url_original, alt: @user.screen_name, width: 64, height: 64, class: "icon img-rounded" .screen_name= link_to @user.screen_name, twitter_user_url(@user.screen_name) - - if @user.registered? + - if @user.registered? && @user.account.active? %ul.records %li %span favorited diff --git a/app/views/users/stats.html.haml b/app/views/users/stats.html.haml index 2cad93f..6e6b685 100644 --- a/app/views/users/stats.html.haml +++ b/app/views/users/stats.html.haml @@ -18,7 +18,7 @@ %dd= @user_twitter.listed_count %dt Bio %dd= raw @user_twitter.description.gsub(/&(?!(amp;|gt;|lt;|quot;|apos;))/, "&") -- if @user.registered? +- if @user.registered? && @user.account.active? %p records %dl.dl-horizontal %dt Favorited diff --git a/collector/connection.rb b/collector/connection.rb index 8a06b3f..c2b2cde 100644 --- a/collector/connection.rb +++ b/collector/connection.rb @@ -59,6 +59,13 @@ module Aclog else @clients[account_id].update(msg) end + when "stop" + account_id = msg["id"] + if @clients[account_id] + @clients[account_id].stop + @clients.delete(account_id) + @logger.info("Received account stop") + end else @logger.info("Unknown message: #{msg}") end diff --git a/collector/stream.rb b/collector/stream.rb index 0fda622..e2bcf05 100644 --- a/collector/stream.rb +++ b/collector/stream.rb @@ -102,6 +102,7 @@ module Aclog def stop @client.connection.stop + log(:info, "Disconnected") end private diff --git a/lib/aclog/receiver/collector_connection.rb b/lib/aclog/receiver/collector_connection.rb index 3d441b1..8b566cc 100644 --- a/lib/aclog/receiver/collector_connection.rb +++ b/lib/aclog/receiver/collector_connection.rb @@ -28,6 +28,12 @@ module Aclog Rails.logger.debug("Sent #{account.id}/#{account.user_id}") end + def send_stop_account(account) + send_object(type: "stop", + id: account.id) + Rails.logger.debug("Sent Stop #{account.id}/#{account.user_id}") + end + def post_init # なにもしない。クライアントが end diff --git a/lib/aclog/receiver/register_server.rb b/lib/aclog/receiver/register_server.rb index 4f8a06c..541efd5 100644 --- a/lib/aclog/receiver/register_server.rb +++ b/lib/aclog/receiver/register_server.rb @@ -11,20 +11,15 @@ module Aclog con_num = account.id % Settings.collector.count con = @connections[con_num] if con - con.send_account(account) - Rails.logger.info("Sent account: connection_number: #{con_num} / account_id: #{account.id}") + if account.active? + con.send_account(account) + else + con.send_stop_account(account) + end else Rails.logger.info("Connection not found: connection_number: #{con_num} / account_id: #{account.id}") end end - - def unregister(account_) - account = Marshal.load(account_) - end - - def unregister(account) - # TODO - end end end end |