From 6a51d0c8a0cbf16bcfda2d3bed0c6769102bbb65 Mon Sep 17 00:00:00 2001 From: james_ <1606304+zz9pzza@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:38:47 +0000 Subject: [PATCH 1/3] Do test still pass on this minimal pull --- app/helpers/resque_executor_wrap_helper.rb | 5 +++++ app/models/bookmark.rb | 2 ++ app/models/concerns/async_with_resque.rb | 18 ++++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 app/helpers/resque_executor_wrap_helper.rb diff --git a/app/helpers/resque_executor_wrap_helper.rb b/app/helpers/resque_executor_wrap_helper.rb new file mode 100644 index 00000000000..aa8d2e48fb3 --- /dev/null +++ b/app/helpers/resque_executor_wrap_helper.rb @@ -0,0 +1,5 @@ +module ResqueExecutorWrap + def around_perform_wrap_executor(*args) + Rails.application.executor.wrap { yield } + end +end diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 2aac480e454..184c86585f3 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -131,6 +131,8 @@ def check_new_external_work after_create :update_work_stats after_destroy :update_work_stats, :update_pseud_index + Resque::Job.extend(ResqueExecutorWrap) + def invalidate_bookmark_count work = Work.where(id: self.bookmarkable_id) if work.present? && self.bookmarkable_type == 'Work' diff --git a/app/models/concerns/async_with_resque.rb b/app/models/concerns/async_with_resque.rb index 8549bcd4d64..3517f8a9159 100644 --- a/app/models/concerns/async_with_resque.rb +++ b/app/models/concerns/async_with_resque.rb @@ -22,14 +22,16 @@ def async(method, *args) # Actually perform the delayed action. def perform(method, *args) - if method.is_a?(Integer) - # TODO: For backwards compatibility, if the "method" is an integer, we - # treat it like an ID and use perform_on_instance instead. But once all - # of the jobs in the queue have been processed (or deleted), we should - # be able to remove this check. - perform_on_instance(method, *args) - else - send(method, *args) + Rails.application.executor.wrap do + if method.is_a?(Integer) + # TODO: For backwards compatibility, if the "method" is an integer, we + # treat it like an ID and use perform_on_instance instead. But once all + # of the jobs in the queue have been processed (or deleted), we should + # be able to remove this check. + perform_on_instance(method, *args) + else + send(method, *args) + end end end From 9579b01189d897d2aee8655c5b246920c87aba34 Mon Sep 17 00:00:00 2001 From: james_ <1606304+zz9pzza@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:48:37 +0000 Subject: [PATCH 2/3] Not a helper --- .../resque_executor_wrap_helper.rb => lib/resque_executor_wrap.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/helpers/resque_executor_wrap_helper.rb => lib/resque_executor_wrap.rb (100%) diff --git a/app/helpers/resque_executor_wrap_helper.rb b/lib/resque_executor_wrap.rb similarity index 100% rename from app/helpers/resque_executor_wrap_helper.rb rename to lib/resque_executor_wrap.rb From 6430513a52dba28989d27e25e09164dfbe61369e Mon Sep 17 00:00:00 2001 From: james_ <1606304+zz9pzza@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:54:37 +0000 Subject: [PATCH 3/3] Apply patten to other classes that enqueue --- app/controllers/challenge_signups_controller.rb | 1 + app/controllers/troubleshooting_controller.rb | 1 + app/jobs/redis_set_job.rb | 2 +- app/models/challenge_assignment.rb | 1 + app/models/challenge_signup_summary.rb | 2 +- app/models/concerns/filterable.rb | 1 + app/models/indexing/index_queue.rb | 1 + app/models/potential_match.rb | 1 + app/models/pseud.rb | 1 + app/models/redis_hit_counter.rb | 1 + app/models/search/async_indexer.rb | 2 +- app/models/search/index_sweeper.rb | 1 + app/models/search/indexer.rb | 1 + app/models/serial_work.rb | 1 + app/models/series.rb | 2 ++ app/models/stat_counter.rb | 2 ++ app/models/tag.rb | 2 ++ app/models/tagging.rb | 2 ++ app/models/user.rb | 2 ++ app/models/work.rb | 2 ++ lib/bookmarkable.rb | 1 + lib/resque_executor_wrap.rb | 2 +- lib/searchable.rb | 1 + 23 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/controllers/challenge_signups_controller.rb b/app/controllers/challenge_signups_controller.rb index 66eeae2b64b..54e634e3172 100644 --- a/app/controllers/challenge_signups_controller.rb +++ b/app/controllers/challenge_signups_controller.rb @@ -3,6 +3,7 @@ class ChallengeSignupsController < ApplicationController include ExportsHelper + Resque::Job.extend(ResqueExecutorWrap) before_action :users_only, except: [:summary, :display_summary, :requests_summary] before_action :load_collection, except: [:index] diff --git a/app/controllers/troubleshooting_controller.rb b/app/controllers/troubleshooting_controller.rb index f1eb0ff4b2b..e8985a576fb 100644 --- a/app/controllers/troubleshooting_controller.rb +++ b/app/controllers/troubleshooting_controller.rb @@ -3,6 +3,7 @@ # A controller used to let admins and tag wranglers perform some # troubleshooting on tags and works. class TroubleshootingController < ApplicationController + Resque::Job.extend(ResqueExecutorWrap) before_action :check_permission_to_wrangle before_action :load_item before_action :check_visibility diff --git a/app/jobs/redis_set_job.rb b/app/jobs/redis_set_job.rb index 1d2206bc480..f5eeb486c18 100644 --- a/app/jobs/redis_set_job.rb +++ b/app/jobs/redis_set_job.rb @@ -35,7 +35,7 @@ def self.batch_size def perform(*args, **kwargs) scan_and_remove(redis, key, batch_size: batch_size) do |batch| - perform_on_batch(batch, *args, **kwargs) + Rails.application.executor.wrap {perform_on_batch(batch, *args, **kwargs)} end end diff --git a/app/models/challenge_assignment.rb b/app/models/challenge_assignment.rb index 714fecdf537..9da0099f5a2 100755 --- a/app/models/challenge_assignment.rb +++ b/app/models/challenge_assignment.rb @@ -80,6 +80,7 @@ def signups_match } scope :posted, -> { joins(WORKS_JOIN).where("challenge_assignments.creation_id IS NOT NULL AND works.posted = 1") } + Resque::Job.extend(ResqueExecutorWrap) # should be faster than unfulfilled scope because no giant left joins def self.unfulfilled_in_collection(collection) diff --git a/app/models/challenge_signup_summary.rb b/app/models/challenge_signup_summary.rb index 305f713abb6..1407407ffac 100644 --- a/app/models/challenge_signup_summary.rb +++ b/app/models/challenge_signup_summary.rb @@ -1,5 +1,5 @@ class ChallengeSignupSummary - + Resque::Job.extend(ResqueExecutorWrap) attr_reader :collection, :challenge def initialize(collection) diff --git a/app/models/concerns/filterable.rb b/app/models/concerns/filterable.rb index bf7f061642f..60663d3395d 100644 --- a/app/models/concerns/filterable.rb +++ b/app/models/concerns/filterable.rb @@ -3,6 +3,7 @@ # A module for types that are supposed to have FilterTaggings, calculated based # on their tags. Includes Taggable. module Filterable + Resque::Job.extend(ResqueExecutorWrap) extend ActiveSupport::Concern include Taggable diff --git a/app/models/indexing/index_queue.rb b/app/models/indexing/index_queue.rb index c1d61cbf913..19bb71c6f10 100644 --- a/app/models/indexing/index_queue.rb +++ b/app/models/indexing/index_queue.rb @@ -1,4 +1,5 @@ class IndexQueue + Resque::Job.extend(ResqueExecutorWrap) BATCH_SIZE = 1000 REDIS = REDIS_GENERAL diff --git a/app/models/potential_match.rb b/app/models/potential_match.rb index 0927aeb660c..2bc2a069366 100644 --- a/app/models/potential_match.rb +++ b/app/models/potential_match.rb @@ -1,4 +1,5 @@ class PotentialMatch < ApplicationRecord + Resque::Job.extend(ResqueExecutorWrap) # We use "-1" to represent all the requested items matching ALL = -1 diff --git a/app/models/pseud.rb b/app/models/pseud.rb index 6dca5d7641b..887a57103f3 100644 --- a/app/models/pseud.rb +++ b/app/models/pseud.rb @@ -2,6 +2,7 @@ class Pseud < ApplicationRecord include Searchable include WorksOwner include Justifiable + Resque::Job.extend(ResqueExecutorWrap) has_one_attached :icon do |attachable| attachable.variant(:standard, resize_to_limit: [100, 100]) diff --git a/app/models/redis_hit_counter.rb b/app/models/redis_hit_counter.rb index 9fdb17ac356..a4c3800863e 100644 --- a/app/models/redis_hit_counter.rb +++ b/app/models/redis_hit_counter.rb @@ -3,6 +3,7 @@ class RedisHitCounter class << self include RedisScanning + Resque::Job.extend(ResqueExecutorWrap) # Records a hit for the given IP address on the given work ID. If the IP # address hasn't visited the work within the current 24 hour block, we diff --git a/app/models/search/async_indexer.rb b/app/models/search/async_indexer.rb index acbe66791d8..4c13db2aa48 100644 --- a/app/models/search/async_indexer.rb +++ b/app/models/search/async_indexer.rb @@ -1,5 +1,5 @@ class AsyncIndexer - + Resque::Job.extend(ResqueExecutorWrap) REDIS = REDIS_GENERAL #################### diff --git a/app/models/search/index_sweeper.rb b/app/models/search/index_sweeper.rb index 865d8cb5e9c..18a37de9595 100644 --- a/app/models/search/index_sweeper.rb +++ b/app/models/search/index_sweeper.rb @@ -1,4 +1,5 @@ class IndexSweeper + Resque::Job.extend(ResqueExecutorWrap) REDIS = AsyncIndexer::REDIS diff --git a/app/models/search/indexer.rb b/app/models/search/indexer.rb index 3142110834e..7f108568e46 100644 --- a/app/models/search/indexer.rb +++ b/app/models/search/indexer.rb @@ -8,6 +8,7 @@ class Indexer Series: %w[BookmarkedSeriesIndexer], ExternalWork: %w[BookmarkedExternalWorkIndexer] }.freeze + Resque::Job.extend(ResqueExecutorWrap) delegate :klass, :klass_with_includes, :index_name, :document_type, to: :class diff --git a/app/models/serial_work.rb b/app/models/serial_work.rb index ae197988ea5..5b0099bda32 100644 --- a/app/models/serial_work.rb +++ b/app/models/serial_work.rb @@ -11,6 +11,7 @@ class SerialWork < ApplicationRecord after_destroy :update_series_index, :update_work_index scope :in_order, -> { order(:position) } + Resque::Job.extend(ResqueExecutorWrap) # If you add or remove a work from a series, make sure restricted? is still accurate def adjust_series_visibility diff --git a/app/models/series.rb b/app/models/series.rb index 8b9ab830f3d..94b737234ba 100644 --- a/app/models/series.rb +++ b/app/models/series.rb @@ -22,6 +22,8 @@ class Series < ApplicationRecord maximum: ArchiveConfig.TITLE_MAX, too_long: ts("must be less than %{max} letters long.", max: ArchiveConfig.TITLE_MAX) + Resque::Job.extend(ResqueExecutorWrap) + # return title.html_safe to overcome escaping done by sanitiser def title read_attribute(:title).try(:html_safe) diff --git a/app/models/stat_counter.rb b/app/models/stat_counter.rb index f362907e8e9..8ae8bd28f6a 100644 --- a/app/models/stat_counter.rb +++ b/app/models/stat_counter.rb @@ -3,6 +3,8 @@ class StatCounter < ApplicationRecord after_commit :enqueue_to_index, on: :update + Resque::Job.extend(ResqueExecutorWrap) + def enqueue_to_index IndexQueue.enqueue(self, :stats) end diff --git a/app/models/tag.rb b/app/models/tag.rb index b8b694a5438..6a82de16423 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -7,6 +7,8 @@ class Tag < ApplicationRecord include Wrangleable include Rails.application.routes.url_helpers + Resque::Job.extend(ResqueExecutorWrap) + NAME = "Tag" # Note: the order of this array is important. diff --git a/app/models/tagging.rb b/app/models/tagging.rb index 63a1617c6b0..41896a873f8 100644 --- a/app/models/tagging.rb +++ b/app/models/tagging.rb @@ -12,6 +12,8 @@ class Tagging < ApplicationRecord after_create :update_filters after_destroy :update_filters + Resque::Job.extend(ResqueExecutorWrap) + def update_filters return unless taggable.is_a?(Filterable) diff --git a/app/models/user.rb b/app/models/user.rb index 47c6c6b3d04..8b79905d65d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,6 +17,8 @@ class User < ApplicationRecord # properly include BackwardsCompatiblePasswordDecryptor + Resque::Job.extend(ResqueExecutorWrap) + # Allows other models to get the current user with User.current_user cattr_accessor :current_user diff --git a/app/models/work.rb b/app/models/work.rb index 0881823f956..f77e897fbf9 100755 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -8,6 +8,8 @@ class Work < ApplicationRecord include WorkChapterCountCaching include Creatable + Resque::Job.extend(ResqueExecutorWrap) + ######################################################################## # ASSOCIATIONS ######################################################################## diff --git a/lib/bookmarkable.rb b/lib/bookmarkable.rb index f0efb4d2246..c9ef3abf179 100644 --- a/lib/bookmarkable.rb +++ b/lib/bookmarkable.rb @@ -1,4 +1,5 @@ module Bookmarkable + Resque::Job.extend(ResqueExecutorWrap) def self.included(bookmarkable) bookmarkable.class_eval do diff --git a/lib/resque_executor_wrap.rb b/lib/resque_executor_wrap.rb index aa8d2e48fb3..1c91eddbf1f 100644 --- a/lib/resque_executor_wrap.rb +++ b/lib/resque_executor_wrap.rb @@ -1,4 +1,4 @@ -module ResqueExecutorWrap +module ResqueExecutorWrap def around_perform_wrap_executor(*args) Rails.application.executor.wrap { yield } end diff --git a/lib/searchable.rb b/lib/searchable.rb index e9bab946743..586aca6c1a0 100644 --- a/lib/searchable.rb +++ b/lib/searchable.rb @@ -1,4 +1,5 @@ module Searchable + Resque::Job.extend(ResqueExecutorWrap) def self.included(searchable) searchable.class_eval do