-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3153: feat: summary table for qualifications r=stack72 a=adamhjk The get_summary endpoint was taking 30+ seconds to respond in production. This commit introduces the idea of 'summary tables', which get updated when the internal provider for the root prop is updated. We take the raw data, and then compute custom tables that cache the data, getting rid of the need to do the complex queries to get the information. This is in a pretty raw state - if we decide that summary tables like this are a pattern we want more broadly, it'll certainly need some refactoring (like moving the summary table code into a single module, etc.) <img src="https://media4.giphy.com/media/NFA61GS9qKZ68/giphy.gif"/> Co-authored-by: Adam Jacob <[email protected]>
- Loading branch information
Showing
7 changed files
with
239 additions
and
68 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
CREATE TABLE summary_qualifications | ||
( | ||
pk ident primary key default ident_create_v1(), | ||
id ident not null default ident_create_v1(), | ||
component_id ident NOT NULL, | ||
component_name text NOT NULL, | ||
tenancy_workspace_pk ident, | ||
visibility_change_set_pk ident NOT NULL DEFAULT ident_nil_v1(), | ||
visibility_deleted_at timestamp with time zone, | ||
created_at timestamp with time zone NOT NULL DEFAULT CLOCK_TIMESTAMP(), | ||
updated_at timestamp with time zone NOT NULL DEFAULT CLOCK_TIMESTAMP(), | ||
total bigint, | ||
warned bigint, | ||
succeeded bigint, | ||
failed bigint | ||
); | ||
|
||
SELECT standard_model_table_constraints_v1('summary_qualifications'); | ||
INSERT INTO standard_models (table_name, table_type, history_event_label_base, history_event_message_name) | ||
VALUES ('summary_qualifications', 'model', 'summary_qualifications', 'Summary Qualifications'); | ||
|
||
CREATE OR REPLACE FUNCTION summary_qualification_update_v1( | ||
this_tenancy jsonb, | ||
this_visibility jsonb, | ||
this_component_id ident, | ||
this_component_name text, | ||
this_total bigint, | ||
this_warned bigint, | ||
this_succeeded bigint, | ||
this_failed bigint, | ||
OUT object json) AS | ||
$$ | ||
DECLARE | ||
this_tenancy_record tenancy_record_v1; | ||
this_visibility_record visibility_record_v1; | ||
this_new_row summary_qualifications%ROWTYPE; | ||
BEGIN | ||
this_tenancy_record := tenancy_json_to_columns_v1(this_tenancy); | ||
this_visibility_record := visibility_json_to_columns_v1(this_visibility); | ||
|
||
INSERT INTO summary_qualifications | ||
(id, component_id, component_name, tenancy_workspace_pk, visibility_change_set_pk, total, warned, succeeded, failed) | ||
VALUES | ||
(this_component_id, this_component_id, this_component_name, this_tenancy_record.tenancy_workspace_pk, this_visibility_record.visibility_change_set_pk, | ||
this_total, this_warned, this_succeeded, this_failed) | ||
ON CONFLICT (id, tenancy_workspace_pk, visibility_change_set_pk) | ||
DO UPDATE SET component_name = this_component_name, total = this_total, warned = this_warned, succeeded = this_succeeded, failed = this_failed | ||
RETURNING * INTO this_new_row; | ||
END | ||
$$ LANGUAGE PLPGSQL VOLATILE; |
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
11 changes: 11 additions & 0 deletions
11
lib/dal/src/queries/summary_qualification/get_summary_qualifications.sql
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,11 @@ | ||
SELECT row_to_json(a) AS object | ||
FROM (SELECT DISTINCT ON (components.id) components.id AS component_id, | ||
summary_qualifications.component_name, | ||
summary_qualifications.total, | ||
summary_qualifications.warned, | ||
summary_qualifications.succeeded, | ||
summary_qualifications.failed | ||
FROM components | ||
INNER JOIN summary_qualifications ON components.id = summary_qualifications.component_id AND components.visibility_change_set_pk = summary_qualifications.visibility_change_set_pk | ||
WHERE in_tenancy_and_visible_v1($1, $2, components) | ||
ORDER BY components.id, components.visibility_change_set_pk DESC, components.visibility_deleted_at DESC) AS a |
Oops, something went wrong.