-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-option-to-order-user-project-contributio…
…ns-by-most-recently-contributed
- Loading branch information
Showing
13 changed files
with
366 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/models/classification_counts/hourly_workflow_classification_count.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module ClassificationCounts | ||
class HourlyWorkflowClassificationCount < ApplicationRecord | ||
self.table_name = 'hourly_classification_count_per_workflow' | ||
attribute :classification_count, :integer | ||
|
||
def readonly? | ||
true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
db/migrate/20240926225916_create_hourly_workflow_classification_count.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true. | ||
|
||
class CreateHourlyWorkflowClassificationCount < ActiveRecord::Migration[7.0] | ||
# we have to disable the migration transaction because creating materialized views within it is not allowed. | ||
|
||
# Due to how the front end pulls project stats (and workflow stats) all in one go, we hit performance issues; especially if a project has multiple workflows. | ||
# We have discovered that having a non-realtime/materialized only continous aggregate for our daily workflow count cagg is more performant than real time. | ||
# We plan to do the following: | ||
# - Update the daily_classification_count_per_workflow to be materialized only (i.e. non-realtime) | ||
# - Create a subsequent realtime cagg that buckets hourly that we will create data retention policies for. The plan is for up to 72 hours worth of hourly workflow classification counts of data. | ||
# - Update workflow query to first query the daily counts first and the query the hourly counts for just the specific date of now. | ||
disable_ddl_transaction! | ||
def up | ||
execute <<~SQL | ||
create materialized view hourly_classification_count_per_workflow | ||
with ( | ||
timescaledb.continuous | ||
) as | ||
select | ||
time_bucket('1 hour', event_time) as hour, | ||
workflow_id, | ||
count(*) as classification_count | ||
from classification_events where event_time > now() - INTERVAL '5 days' | ||
group by hour, workflow_id; | ||
SQL | ||
end | ||
|
||
def down | ||
execute <<~SQL | ||
DROP materialized view hourly_classification_count_per_workflow; | ||
SQL | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
db/migrate/20240926231010_add_refresh_policy_for_hourly_workflow_count.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddRefreshPolicyForHourlyWorkflowCount < ActiveRecord::Migration[7.0] | ||
disable_ddl_transaction! | ||
def up | ||
execute <<~SQL | ||
SELECT add_continuous_aggregate_policy('hourly_classification_count_per_workflow',start_offset => INTERVAL '5 days', end_offset => INTERVAL '30 minutes', schedule_interval => INTERVAL '1 h'); | ||
SQL | ||
end | ||
|
||
def down | ||
execute <<~SQL | ||
SELECT remove_continuous_aggregate_policy('hourly_classification_count_per_workflow'); | ||
SQL | ||
end | ||
end |
Oops, something went wrong.