Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request mastodon#1316 from pixiv/remove_switch_point
Browse files Browse the repository at this point in the history
remove switch point
  • Loading branch information
abcang authored Oct 23, 2019
2 parents a149dc0 + 13f235b commit 816c859
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 105 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ gem 'sentry-raven'
gem 'type_attributes'
gem 'activerecord-import'
gem 'elasticsearch-model', '~> 5.0'
gem 'switch_point'
gem 'exponent-server-sdk'
gem 'recaptcha'

Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,6 @@ GEM
multi_json (~> 1.8)
strong_migrations (0.2.2)
activerecord (>= 3.2.0)
switch_point (0.8.0)
activerecord (>= 3.2.0)
temple (0.8.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
Expand Down Expand Up @@ -849,7 +847,6 @@ DEPENDENCIES
stoplight (~> 2.1.3)
streamio-ffmpeg (~> 3.0)
strong_migrations (~> 0.2)
switch_point
tty-command (~> 0.8)
tty-prompt (~> 0.16)
twitter-text (~> 1.14)
Expand Down
9 changes: 0 additions & 9 deletions app/controllers/pawoo/sitemap/application_controller.rb

This file was deleted.

15 changes: 3 additions & 12 deletions app/controllers/pawoo/sitemap/status_indexes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
# frozen_string_literal: true

class Pawoo::Sitemap::StatusIndexesController < Pawoo::Sitemap::ApplicationController
class Pawoo::Sitemap::StatusIndexesController < ApplicationController
def index
read_from_slave do
@count = Pawoo::Sitemap::Status.page_count
end
@count = Pawoo::Sitemap::Status.page_count
end

def show
page = params[:page]
sitemap = Pawoo::Sitemap::Status.new(page)

if sitemap.cached?
read_from_slave do
@status_pages = sitemap.query.load
end
else
@status_pages = []
end
@accounts = sitemap.cached? ? sitemap.query.load : []
end
end
15 changes: 3 additions & 12 deletions app/controllers/pawoo/sitemap/user_indexes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
# frozen_string_literal: true

class Pawoo::Sitemap::UserIndexesController < Pawoo::Sitemap::ApplicationController
class Pawoo::Sitemap::UserIndexesController < ApplicationController
def index
read_from_slave do
@count = Pawoo::Sitemap::User.page_count
end
@count = Pawoo::Sitemap::User.page_count
end

def show
page = params[:page]
sitemap = Pawoo::Sitemap::User.new(page)

if sitemap.cached?
read_from_slave do
@accounts = sitemap.query.load
end
else
@accounts = []
end
@accounts = sitemap.cached? ? sitemap.query.load : []
end
end
1 change: 0 additions & 1 deletion app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
include Remotable
use_switch_point(:pawoo_slave)
end
7 changes: 0 additions & 7 deletions app/services/concerns/pawoo/slave_reader.rb

This file was deleted.

22 changes: 9 additions & 13 deletions app/services/pawoo/refresh_popular_account_service.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Pawoo::RefreshPopularAccountService
include Pawoo::SlaveReader

ACTIVE_ACCOUNT_DURATION = 2.weeks
RECENT_MEDIA_DURATION = 1.month
REDIS_KEY = 'pawoo:popular_account_ids'
Expand All @@ -14,18 +12,16 @@ def initialize
end

def call
read_from_slave do
load_active_accounts
load_pixiv_followers_count
load_latest_media_statuses

popular_account_tuples = []
@accounts_infomations.each do |account_id, info|
score = calc_score(info)
popular_account_tuples << [score, account_id] if score > MIN_SCORE
end
store_to_redis(popular_account_tuples)
load_active_accounts
load_pixiv_followers_count
load_latest_media_statuses

popular_account_tuples = []
@accounts_infomations.each do |account_id, info|
score = calc_score(info)
popular_account_tuples << [score, account_id] if score > MIN_SCORE
end
store_to_redis(popular_account_tuples)
end

private
Expand Down
30 changes: 13 additions & 17 deletions app/services/trend_tag_service.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class TrendTagService < BaseService
include Pawoo::SlaveReader

SPAN = 60.minutes
TREND_HISTORIES_KEY = 'trend_histories'
TREND_LENGTH = 3
Expand Down Expand Up @@ -49,24 +47,22 @@ def +(other)
end

def call(time = Time.current)
read_from_slave do
statuses = recent_public_statuses(time)
current_tag_scores = build_tag_scores_from_statuses(statuses)
lpush_current_tag_scores(current_tag_scores)
statuses = recent_public_statuses(time)
current_tag_scores = build_tag_scores_from_statuses(statuses)
lpush_current_tag_scores(current_tag_scores)

# 履歴の数がHISTORY_COUNTより少ない場合はトレンドを出すことができないため、空配列を返す
return [] if redis.llen(TREND_HISTORIES_KEY) + 1 < HISTORY_COUNT
# 履歴の数がHISTORY_COUNTより少ない場合はトレンドを出すことができないため、空配列を返す
return [] if redis.llen(TREND_HISTORIES_KEY) + 1 < HISTORY_COUNT

# historyから過去のcurrent_tag_scoresを取り出す
tag_score_histories = redis.lrange(TREND_HISTORIES_KEY, 1, -1).map do |history_tag_score|
JSON.parse(history_tag_score).map { |tag_score_attributes| TagScore.new(tag_score_attributes) }
end
# historyから過去のcurrent_tag_scoresを取り出す
tag_score_histories = redis.lrange(TREND_HISTORIES_KEY, 1, -1).map do |history_tag_score|
JSON.parse(history_tag_score).map { |tag_score_attributes| TagScore.new(tag_score_attributes) }
end

# 現在のトレンドを計算する
tag_scores = current_trend_tag_scores(current_tag_scores, tag_score_histories)
tag_scores.map(&:tag_name).tap do |tag_names|
TrendTag.update_trend_tags(tag_names)
end
# 現在のトレンドを計算する
tag_scores = current_trend_tag_scores(current_tag_scores, tag_score_histories)
tag_scores.map(&:tag_name).tap do |tag_names|
TrendTag.update_trend_tags(tag_names)
end
end

Expand Down
9 changes: 2 additions & 7 deletions app/workers/pawoo/sitemap/prepare_statuses_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class Pawoo::Sitemap::PrepareStatusesWorker
include Sidekiq::Worker
include Pawoo::SlaveReader

sidekiq_options queue: 'pull', unique: :until_executed, retry: 0

Expand Down Expand Up @@ -39,14 +38,10 @@ def redis_lock_key
end

def prepare_sitemap(page)
read_from_slave do
Pawoo::Sitemap::Status.new(page).prepare
end
Pawoo::Sitemap::Status.new(page).prepare
end

def page_count
read_from_slave do
Pawoo::Sitemap::Status.page_count
end
Pawoo::Sitemap::Status.page_count
end
end
9 changes: 2 additions & 7 deletions app/workers/pawoo/sitemap/prepare_users_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class Pawoo::Sitemap::PrepareUsersWorker
include Sidekiq::Worker
include Pawoo::SlaveReader

sidekiq_options queue: 'pull', unique: :until_executed, retry: 0

Expand Down Expand Up @@ -39,14 +38,10 @@ def redis_lock_key
end

def prepare_sitemap(page)
read_from_slave do
Pawoo::Sitemap::User.new(page).prepare
end
Pawoo::Sitemap::User.new(page).prepare
end

def page_count
read_from_slave do
Pawoo::Sitemap::User.page_count
end
Pawoo::Sitemap::User.page_count
end
end
11 changes: 0 additions & 11 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ development: &development
password: <%= ENV['DB_PASS'] %>
host: <%= ENV['DB_HOST'] %>
port: <%= ENV['DB_PORT'] %>
development_pawoo_slave:
<<: *development
# NOTE: SlaveDB参照の動作確認をしたい場合は、以下の名前でDBを用意してコメントアウトをはずす
# database: pawoo_development_slave

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
Expand All @@ -28,7 +24,6 @@ test: &test
password: <%= ENV['DB_PASS'] %>
host: <%= ENV['DB_HOST'] %>
port: <%= ENV['DB_PORT'] %>
test_pawoo_slave: *test

production: &production
<<: *default
Expand All @@ -38,9 +33,3 @@ production: &production
host: <%= ENV['DB_HOST'] || 'localhost' %>
port: <%= ENV['DB_PORT'] || 5432 %>
prepared_statements: <%= ENV['PREPARED_STATEMENTS'] || 'true' %>
production_pawoo_slave:
<<: *production
username: <%= ENV['PAWOO_DB_USER_SLAVE'] %>
password: <%= ENV['PAWOO_DB_PASS_SLAVE'] %>
host: <%= ENV['PAWOO_DB_HOST_SLAVE'] || 'localhost' %>
port: <%= ENV['PAWOO_DB_PORT_SLAVE'] || 5432 %>
5 changes: 0 additions & 5 deletions config/initializers/switch_point.rb

This file was deleted.

0 comments on commit 816c859

Please sign in to comment.