Skip to content

Commit

Permalink
Remove usage of COALESCE from dashboard chart (#1306)
Browse files Browse the repository at this point in the history
* Fix COALESCE timestamp generation

* Remove coalesce altogether

* Fix linting violation

---------

Co-authored-by: Ben Sheldon [he/him] <[email protected]>
  • Loading branch information
bananatron and bensheldon authored Nov 28, 2024
1 parent 54103a5 commit ee33626
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/charts/good_job/performance_index_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PerformanceIndexChart < BaseChart
def data
table_name = GoodJob::Execution.table_name

sum_query = Arel.sql(GoodJob::Job.pg_or_jdbc_query(<<~SQL.squish))
sum_query = <<~SQL.squish
SELECT *
FROM generate_series(
date_trunc('hour', $1::timestamp),
Expand Down
2 changes: 1 addition & 1 deletion app/charts/good_job/performance_show_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def data
table_name = GoodJob::Execution.table_name

interval_entries = BUCKET_INTERVALS.map { "interval '#{_1}'" }.join(",")
sum_query = Arel.sql(GoodJob::Job.pg_or_jdbc_query(<<~SQL.squish))
sum_query = <<~SQL.squish
SELECT
WIDTH_BUCKET(duration, ARRAY[#{interval_entries}]) as bucket_index,
COUNT(WIDTH_BUCKET(duration, ARRAY[#{interval_entries}])) AS count
Expand Down
6 changes: 2 additions & 4 deletions app/charts/good_job/scheduled_by_queue_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def initialize(filter)
end

def data
table_name = GoodJob::Job.table_name

count_query = Arel.sql(GoodJob::Job.pg_or_jdbc_query(<<~SQL.squish))
count_query = <<~SQL.squish
SELECT *
FROM generate_series(
date_trunc('hour', $1::timestamp),
Expand All @@ -23,7 +21,7 @@ def data
queue_name,
count(*) AS count
FROM (
#{@filter.filtered_query.except(:select, :order).select('queue_name', "COALESCE(#{table_name}.scheduled_at, #{table_name}.created_at)::timestamp AS scheduled_at").to_sql}
#{@filter.filtered_query.except(:select, :order).select(:queue_name, :scheduled_at).to_sql}
) sources
GROUP BY date_trunc('hour', scheduled_at), queue_name
) sources ON sources.scheduled_at = timestamp
Expand Down

0 comments on commit ee33626

Please sign in to comment.