From cea8018fb78c23a4c7716a3da3b28374568a7b1a Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:29:08 +0200 Subject: [PATCH] Remove old compatibility code --- app/models/concerns/good_job/advisory_lockable.rb | 9 +-------- app/models/concerns/good_job/filterable.rb | 13 ++----------- app/models/good_job/batch_record.rb | 6 +----- demo/config/environments/test.rb | 6 +----- .../concerns/good_job/advisory_lockable_spec.rb | 6 +++--- .../active_job_extensions/concurrency_spec.rb | 10 ++++------ spec/support/rails_versions.rb | 6 ------ 7 files changed, 12 insertions(+), 44 deletions(-) delete mode 100644 spec/support/rails_versions.rb diff --git a/app/models/concerns/good_job/advisory_lockable.rb b/app/models/concerns/good_job/advisory_lockable.rb index e40ef0c8e..588ba130a 100644 --- a/app/models/concerns/good_job/advisory_lockable.rb +++ b/app/models/concerns/good_job/advisory_lockable.rb @@ -44,8 +44,7 @@ module AdvisoryLockable cte_table = Arel::Table.new(:rows) cte_query = original_query.select(primary_key, column).except(:limit) cte_query = cte_query.limit(select_limit) if select_limit - cte_type = supports_cte_materialization_specifiers? ? :MATERIALIZED : :"" - composed_cte = Arel::Nodes::As.new(cte_table, Arel::Nodes::UnaryOperation.new(cte_type, cte_query.arel)) + composed_cte = Arel::Nodes::As.new(cte_table, Arel::Nodes::UnaryOperation.new(:MATERIALIZED, cte_query.arel)) lock_condition = "#{function}(('x' || substr(md5(#{connection.quote(table_name)} || '-' || #{connection.quote_table_name(cte_table.name)}.#{connection.quote_column_name(column)}::text), 1, 16))::bit(64)::bigint)" query = cte_table.project(cte_table[:id]) @@ -281,12 +280,6 @@ def _advisory_lockable_column advisory_lockable_column || primary_key end - def supports_cte_materialization_specifiers? - return @_supports_cte_materialization_specifiers if defined?(@_supports_cte_materialization_specifiers) - - @_supports_cte_materialization_specifiers = connection.postgresql_version >= 120000 - end - # Postgres advisory unlocking function for the class # @param function [String, Symbol] name of advisory lock or unlock function # @return [Boolean] diff --git a/app/models/concerns/good_job/filterable.rb b/app/models/concerns/good_job/filterable.rb index bd2599c5f..15aaf18dd 100644 --- a/app/models/concerns/good_job/filterable.rb +++ b/app/models/concerns/good_job/filterable.rb @@ -36,18 +36,9 @@ module Filterable # TODO: turn this into proper bind parameters in Arel tsvector = "(to_tsvector('english', id::text) || to_tsvector('english', COALESCE(active_job_id::text, '')) || to_tsvector('english', serialized_params) || to_tsvector('english', COALESCE(error, '')) || to_tsvector('english', COALESCE(array_to_string(labels, ' '), '')))" - to_tsquery_function = database_supports_websearch_to_tsquery? ? 'websearch_to_tsquery' : 'plainto_tsquery' - where("#{tsvector} @@ #{to_tsquery_function}(?)", query) - .order(sanitize_sql_for_order([Arel.sql("ts_rank(#{tsvector}, #{to_tsquery_function}(?))"), query]) => 'DESC') + where("#{tsvector} @@ websearch_to_tsquery(?)", query) + .order(sanitize_sql_for_order([Arel.sql("ts_rank(#{tsvector}, websearch_to_tsquery(?))"), query]) => 'DESC') end) end - - class_methods do - def database_supports_websearch_to_tsquery? - return @_database_supports_websearch_to_tsquery if defined?(@_database_supports_websearch_to_tsquery) - - @_database_supports_websearch_to_tsquery = connection.postgresql_version >= 110000 - end - end end end diff --git a/app/models/good_job/batch_record.rb b/app/models/good_job/batch_record.rb index bf162d58c..60081ec23 100644 --- a/app/models/good_job/batch_record.rb +++ b/app/models/good_job/batch_record.rb @@ -84,11 +84,7 @@ def self.load(value) end end - if Rails.gem_version < Gem::Version.new('6.1.0.alpha') - # serialize does not yet take a default value, must set via Attributes API - attribute :serialized_properties, :json, default: -> { {} } - serialize :serialized_properties, PropertySerializer - elsif Rails.gem_version < Gem::Version.new('7.1.0.alpha') + if Rails.gem_version < Gem::Version.new('7.1.0.alpha') serialize :serialized_properties, PropertySerializer, default: -> { {} } else serialize :serialized_properties, coder: PropertySerializer, default: -> { {} } diff --git a/demo/config/environments/test.rb b/demo/config/environments/test.rb index 20a5dcd15..ea1cc375f 100644 --- a/demo/config/environments/test.rb +++ b/demo/config/environments/test.rb @@ -13,11 +13,7 @@ config.active_job.queue_adapter = :test # Raises error for missing translations. - if Gem::Version.new(Rails.version) < Gem::Version.new('6.1') - config.action_view.raise_on_missing_translations = true - else - config.i18n.raise_on_missing_translations = true - end + config.i18n.raise_on_missing_translations = true config.colorize_logging = false if ENV["CI"] if ActiveModel::Type::Boolean.new.cast(ENV['RAILS_LOG_TO_STDOUT']) diff --git a/spec/app/models/concerns/good_job/advisory_lockable_spec.rb b/spec/app/models/concerns/good_job/advisory_lockable_spec.rb index 15d019e86..e11d1db67 100644 --- a/spec/app/models/concerns/good_job/advisory_lockable_spec.rb +++ b/spec/app/models/concerns/good_job/advisory_lockable_spec.rb @@ -50,7 +50,7 @@ SELECT "good_jobs".* FROM "good_jobs" WHERE "good_jobs"."id" IN ( - WITH "rows" AS #{'MATERIALIZED' if model_class.supports_cte_materialization_specifiers?} ( + WITH "rows" AS MATERIALIZED ( SELECT "good_jobs"."id", "good_jobs"."id" FROM "good_jobs" WHERE "good_jobs"."priority" = 99 @@ -73,7 +73,7 @@ SELECT "good_jobs".* FROM "good_jobs" WHERE "good_jobs"."id" IN ( - WITH "rows" AS #{'MATERIALIZED' if model_class.supports_cte_materialization_specifiers?} ( + WITH "rows" AS MATERIALIZED ( SELECT "good_jobs"."id", "good_jobs"."queue_name" FROM "good_jobs" ORDER BY "good_jobs"."priority" DESC @@ -95,7 +95,7 @@ SELECT "good_jobs".* FROM "good_jobs" WHERE "good_jobs"."id" IN ( - WITH "rows" AS #{'MATERIALIZED' if model_class.supports_cte_materialization_specifiers?} ( + WITH "rows" AS MATERIALIZED ( SELECT "good_jobs"."id", "good_jobs"."active_job_id" FROM "good_jobs" LIMIT 1000 diff --git a/spec/lib/good_job/active_job_extensions/concurrency_spec.rb b/spec/lib/good_job/active_job_extensions/concurrency_spec.rb index 8310e39e0..afb48db97 100644 --- a/spec/lib/good_job/active_job_extensions/concurrency_spec.rb +++ b/spec/lib/good_job/active_job_extensions/concurrency_spec.rb @@ -51,7 +51,7 @@ def perform(name:) end describe '.good_job_control_concurrency_with' do - describe 'total_limit:', :skip_rails_5 do + describe 'total_limit:' do before do TestJob.good_job_control_concurrency_with( total_limit: -> { 1 }, @@ -75,7 +75,7 @@ def perform(name:) end end - describe 'enqueue_limit:', :skip_rails_5 do + describe 'enqueue_limit:' do before do TestJob.good_job_control_concurrency_with( enqueue_limit: -> { 2 }, @@ -99,10 +99,8 @@ def perform(name:) expect(GoodJob::Job.where(concurrency_key: "Bob").count).to eq 1 expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Aborted enqueue of TestJob \(Job ID: .*\) because the concurrency key 'Alice' has reached its enqueue limit of 2 jobs/)).exactly(:once) - if ActiveJob.gem_version >= Gem::Version.new("6.1.0") - expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Enqueued TestJob \(Job ID: .*\) to \(default\) with arguments: {:name=>"Alice"}/)).exactly(:twice) - expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Enqueued TestJob \(Job ID: .*\) to \(default\) with arguments: {:name=>"Bob"}/)).exactly(:once) - end + expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Enqueued TestJob \(Job ID: .*\) to \(default\) with arguments: {:name=>"Alice"}/)).exactly(:twice) + expect(TestJob.logger.formatter).to have_received(:call).with("INFO", anything, anything, a_string_matching(/Enqueued TestJob \(Job ID: .*\) to \(default\) with arguments: {:name=>"Bob"}/)).exactly(:once) end it 'excludes jobs that are already executing/locked' do diff --git a/spec/support/rails_versions.rb b/spec/support/rails_versions.rb deleted file mode 100644 index 8a8eb47ba..000000000 --- a/spec/support/rails_versions.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -RSpec.configure do |c| - less_than_rails_6 = Gem::Version.new(Rails.version) < Gem::Version.new('6') - c.filter_run_excluding(:skip_rails_5) if less_than_rails_6 -end