Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid including unnecessary pg_locks references when counting jobs #789

Merged
merged 1 commit into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/filters/good_job/base_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(params, base_query = nil)
def records
after_scheduled_at = params[:after_scheduled_at].present? ? Time.zone.parse(params[:after_scheduled_at]) : nil

filtered_query.display_all(
query_for_records.display_all(
after_scheduled_at: after_scheduled_at,
after_id: params[:after_id]
).limit(params.fetch(:limit, DEFAULT_LIMIT))
Expand Down Expand Up @@ -62,6 +62,10 @@ def filtered_count

private

def query_for_records
raise NotImplementedError
end

def default_base_query
raise NotImplementedError
end
Expand Down
8 changes: 6 additions & 2 deletions app/filters/good_job/jobs_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module GoodJob
class JobsFilter < BaseFilter
def states
query = filtered_query(params.except(:state)).unscope(:select)
query = filtered_query(params.except(:state))
{
'scheduled' => query.scheduled.count,
'retried' => query.retried.count,
Expand All @@ -14,7 +14,7 @@ def states
end

def filtered_query(filter_params = params)
query = base_query.includes(:executions).includes_advisory_locks
query = base_query

query = query.job_class(filter_params[:job_class]) if filter_params[:job_class].present?
query = query.where(queue_name: filter_params[:queue_name]) if filter_params[:queue_name].present?
Expand Down Expand Up @@ -47,6 +47,10 @@ def filtered_count

private

def query_for_records
filtered_query.includes(:executions).includes_advisory_locks
end

def default_base_query
GoodJob::Job.all
end
Expand Down