-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2686) Summary Fixes #2604 Time to review: 60 mins Changes proposed Change incremental index process to load from queue table. Handle edge cases for updates - updates will re-index the whole opportunity Context for reviewers WIP for now as we add testing scenarios. Initial draft to review implementation. Additional information See unit tests.
- Loading branch information
1 parent
06ece75
commit e15a545
Showing
6 changed files
with
215 additions
and
15 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
api/src/db/migrations/versions/2024_10_31_remove_has_update_column_from_.py
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,98 @@ | ||
"""Remove has_update column from opportunity_search_index_queue | ||
Revision ID: 8b96ade6f6a2 | ||
Revises: a8ebde13a18a | ||
Create Date: 2024-10-31 16:57:43.256710 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "8b96ade6f6a2" | ||
down_revision = "a8ebde13a18a" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
create_old_trigger_function = """ | ||
CREATE OR REPLACE FUNCTION update_opportunity_search_queue() | ||
RETURNS TRIGGER AS $$ | ||
DECLARE | ||
opp_id bigint; | ||
BEGIN | ||
-- Determine the opportunity_id based on the table | ||
CASE TG_TABLE_NAME | ||
WHEN 'link_opportunity_summary_funding_instrument' THEN | ||
opp_id := (SELECT opportunity_id FROM api.opportunity_summary WHERE opportunity_summary_id = NEW.opportunity_summary_id); | ||
WHEN 'link_opportunity_summary_funding_category' THEN | ||
opp_id := (SELECT opportunity_id FROM api.opportunity_summary WHERE opportunity_summary_id = NEW.opportunity_summary_id); | ||
WHEN 'link_opportunity_summary_applicant_type' THEN | ||
opp_id := (SELECT opportunity_id FROM api.opportunity_summary WHERE opportunity_summary_id = NEW.opportunity_summary_id); | ||
WHEN 'opportunity_summary' THEN | ||
opp_id := NEW.opportunity_id; | ||
WHEN 'current_opportunity_summary' THEN | ||
opp_id := NEW.opportunity_id; | ||
ELSE | ||
opp_id := NEW.opportunity_id; | ||
END CASE; | ||
INSERT INTO api.opportunity_search_index_queue (opportunity_id, has_update) | ||
VALUES (opp_id, TRUE) | ||
ON CONFLICT (opportunity_id) | ||
DO UPDATE SET has_update = TRUE, updated_at = CURRENT_TIMESTAMP; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
""" | ||
|
||
create_trigger_function = """ | ||
CREATE OR REPLACE FUNCTION update_opportunity_search_queue() | ||
RETURNS TRIGGER AS $$ | ||
DECLARE | ||
opp_id bigint; | ||
BEGIN | ||
-- Determine the opportunity_id based on the table | ||
CASE TG_TABLE_NAME | ||
WHEN 'link_opportunity_summary_funding_instrument' THEN | ||
opp_id := (SELECT opportunity_id FROM api.opportunity_summary WHERE opportunity_summary_id = NEW.opportunity_summary_id); | ||
WHEN 'link_opportunity_summary_funding_category' THEN | ||
opp_id := (SELECT opportunity_id FROM api.opportunity_summary WHERE opportunity_summary_id = NEW.opportunity_summary_id); | ||
WHEN 'link_opportunity_summary_applicant_type' THEN | ||
opp_id := (SELECT opportunity_id FROM api.opportunity_summary WHERE opportunity_summary_id = NEW.opportunity_summary_id); | ||
WHEN 'opportunity_summary' THEN | ||
opp_id := NEW.opportunity_id; | ||
WHEN 'current_opportunity_summary' THEN | ||
opp_id := NEW.opportunity_id; | ||
ELSE | ||
opp_id := NEW.opportunity_id; | ||
END CASE; | ||
INSERT INTO api.opportunity_search_index_queue (opportunity_id) | ||
VALUES (opp_id) | ||
ON CONFLICT (opportunity_id) | ||
DO NOTHING; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
""" | ||
|
||
|
||
def upgrade(): | ||
# Update the trigger function | ||
op.execute(create_trigger_function) | ||
|
||
op.drop_column("opportunity_search_index_queue", "has_update", schema="api") | ||
|
||
|
||
def downgrade(): | ||
op.execute(create_old_trigger_function) | ||
|
||
op.add_column( | ||
"opportunity_search_index_queue", | ||
sa.Column("has_update", sa.BOOLEAN(), autoincrement=False, nullable=False), | ||
schema="api", | ||
) |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.