remove id pk from follows, use composite index
This commit is contained in:
13
.vscode/launch.json
vendored
Normal file
13
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "RSpec - active spec file only",
|
||||
"type": "Ruby",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/bin/rspec",
|
||||
"args": ["-I", "${workspaceRoot}", "${file}"],
|
||||
"showDebuggerOutput": true
|
||||
}
|
||||
]
|
||||
}
|
||||
1
Gemfile
1
Gemfile
@@ -110,6 +110,7 @@ gem "pluck_each"
|
||||
gem "good_job"
|
||||
gem "zstd-ruby"
|
||||
gem "rszr"
|
||||
gem "composite_primary_keys", "~> 14.0"
|
||||
|
||||
gem "pg_query", ">= 2"
|
||||
gem "pghero", git: "https://github.com/dymk/pghero", ref: "e314f99"
|
||||
|
||||
@@ -103,6 +103,8 @@ GEM
|
||||
xpath (~> 3.2)
|
||||
coderay (1.1.3)
|
||||
colorize (0.8.1)
|
||||
composite_primary_keys (14.0.6)
|
||||
activerecord (~> 7.0.2)
|
||||
concurrent-ruby (1.2.0)
|
||||
concurrent-ruby-edge (0.7.0)
|
||||
concurrent-ruby (~> 1.2.0)
|
||||
@@ -377,6 +379,7 @@ DEPENDENCIES
|
||||
bootsnap
|
||||
capybara
|
||||
colorize
|
||||
composite_primary_keys (~> 14.0)
|
||||
concurrent-ruby-edge
|
||||
concurrent-ruby-ext
|
||||
curb
|
||||
|
||||
@@ -88,7 +88,6 @@ class Domain::Fa::Job::FavsJob < Domain::Fa::Job::Base
|
||||
else
|
||||
"https://www.furaffinity.net/favorites/#{@user.url_name}/"
|
||||
end
|
||||
|
||||
response = http_client.get(url, caused_by_entry: best_caused_by_entry)
|
||||
@first_job_entry ||= response.log_entry
|
||||
if response.status_code != 200
|
||||
@@ -154,6 +153,7 @@ class Domain::Fa::Job::FavsJob < Domain::Fa::Job::Base
|
||||
fa_id: fa_id,
|
||||
caused_by_entry: best_caused_by_entry,
|
||||
})
|
||||
# sleep 100000
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ class Domain::Fa::Job::ScanPostJob < Domain::Fa::Job::Base
|
||||
@post = args[:post] || begin
|
||||
Domain::Fa::Post.find_or_initialize_by(fa_id: args[:fa_id])
|
||||
end
|
||||
|
||||
@caused_by_entry = args[:caused_by_entry]
|
||||
@force_scan = !!args[:force_scan]
|
||||
logger.prefix = proc { "[fa_id #{@post.fa_id.to_s.bold} / #{@post.state.bold}]" }
|
||||
|
||||
@@ -45,10 +45,12 @@ class Domain::Fa::Job::UserFollowsJob < Domain::Fa::Job::Base
|
||||
"updated follows list to #{@user.follows.count.to_s.bold} users"
|
||||
}) do
|
||||
ReduxApplicationRecord.transaction do
|
||||
@user.follower_joins.where(followed_id: to_remove).delete_all
|
||||
if to_remove.any?
|
||||
@user.follower_joins.where(followed_id: to_remove).delete_all
|
||||
end
|
||||
@user.follower_joins.insert_all!(to_add.map do |id|
|
||||
{ followed_id: id }
|
||||
end) unless to_add.empty?
|
||||
end) if to_add.any?
|
||||
@user.scanned_follows_at = Time.now
|
||||
@user.save!
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Domain::Fa::Follow < ReduxApplicationRecord
|
||||
self.table_name = "domain_fa_follows"
|
||||
self.primary_keys = :follower_id, :followed_id
|
||||
|
||||
belongs_to :follower,
|
||||
class_name: "::Domain::Fa::User"
|
||||
|
||||
@@ -14,6 +14,9 @@ module ReduxScraper
|
||||
config.active_record.legacy_connection_handling = false
|
||||
config.autoload_paths << config.root.join("app/lib")
|
||||
|
||||
# all environments use good_job (in external execution mode)
|
||||
config.active_job.queue_adapter = :good_job
|
||||
|
||||
# Configuration for the application, engines, and railties goes here.
|
||||
#
|
||||
# These settings can be overridden in specific environments using the files
|
||||
|
||||
@@ -69,7 +69,6 @@ Rails.application.configure do
|
||||
# Use a real queuing backend for Active Job (and separate queues per environment).
|
||||
# config.active_job.queue_adapter = :resque
|
||||
# config.active_job.queue_name_prefix = "legacy_explorer_production"
|
||||
|
||||
config.action_mailer.perform_caching = false
|
||||
|
||||
# Ignore bad email addresses and do not raise email delivery errors.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Rails.application.configure do
|
||||
# GoodJob configuration - applies to all environments (including test)
|
||||
config.active_job.queue_adapter = :good_job
|
||||
|
||||
config.good_job.inline_execution_respects_schedule = true
|
||||
config.good_job.active_record_parent_class = "ReduxApplicationRecord"
|
||||
config.good_job.retry_on_unhandled_error = true
|
||||
@@ -14,7 +14,7 @@ Rails.application.configure do
|
||||
config.good_job.logger = Logger.new(STDOUT)
|
||||
config.good_job.logger.level = :warn
|
||||
|
||||
if Rails.env.worker? || Rails.env.test?
|
||||
if Rails.env.worker?
|
||||
config.good_job.execution_mode = :async
|
||||
config.good_job.on_thread_error = ->(exception) { Rails.logger.error("GoodJob exception: #{exception}") }
|
||||
else
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class RemovePkFromFollows < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
remove_index :domain_fa_follows, :follower_id
|
||||
remove_index :domain_fa_follows, :followed_id
|
||||
add_index :domain_fa_follows, [:follower_id, :followed_id], unique: true
|
||||
add_index :domain_fa_follows, [:followed_id, :follower_id]
|
||||
remove_column :domain_fa_follows, :id, :bigint
|
||||
end
|
||||
end
|
||||
8
db/schema.rb
generated
8
db/schema.rb
generated
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_05_20_001257) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_05_23_162724) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
enable_extension "pg_trgm"
|
||||
@@ -761,11 +761,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_20_001257) do
|
||||
t.index ["user_id"], name: "index_domain_fa_favs_on_user_id"
|
||||
end
|
||||
|
||||
create_table "domain_fa_follows", force: :cascade do |t|
|
||||
create_table "domain_fa_follows", id: false, force: :cascade do |t|
|
||||
t.bigint "follower_id", null: false
|
||||
t.bigint "followed_id", null: false
|
||||
t.index ["followed_id"], name: "index_domain_fa_follows_on_followed_id"
|
||||
t.index ["follower_id"], name: "index_domain_fa_follows_on_follower_id"
|
||||
t.index ["followed_id", "follower_id"], name: "index_domain_fa_follows_on_followed_id_and_follower_id"
|
||||
t.index ["follower_id", "followed_id"], name: "index_domain_fa_follows_on_follower_id_and_followed_id", unique: true
|
||||
end
|
||||
|
||||
create_table "domain_fa_posts", force: :cascade do |t|
|
||||
|
||||
@@ -43,7 +43,7 @@ describe Domain::Fa::UserFactor do
|
||||
factors: Domain::Fa::UserFactor::FACTORS_WIDTHS,
|
||||
)
|
||||
query = Enumerator.new do |e|
|
||||
Domain::Fa::Follow.all.find_each do |follow|
|
||||
Domain::Fa::Follow.find_each do |follow|
|
||||
e << follow
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user