-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TN-3291 implement caching of research data, for performance improveme…
…nt (#4382) Reports from the field - the generation of research_data has become unreliable due to time it takes to build report. Now retaining a table of cached values, one row per questionnaire response, for a responsive report generation. Primary concern will be with cache-invalidation, especially on an org change of research protocol or a user's consent date change. There is now a scheduled job that runs daily, to seek out any overlooked QNRs missing from this new cache table `research_data`. A dry run of the prod db: ``` "found 92748 questionnaire responses missing from research_data cache" [...] ""Task portal.tasks.cache_research_data_task[f87d7130-d2b2-4413-a461-61cf3ebc9594] succeeded in 32897.385058208994s" ``` thereafter, it will generally find zero, as we immediately update on QNR put/post.
- Loading branch information
Showing
13 changed files
with
336 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Add research_data table, to hold questionnaire response research data in a cache | ||
Revision ID: daee63f50d35 | ||
Revises: cf586ed4f043 | ||
Create Date: 2024-05-21 17:00:58.204998 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'daee63f50d35' | ||
down_revision = '6120fcfc474a' | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
'research_data', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('subject_id', sa.Integer(), nullable=False), | ||
sa.Column('questionnaire_response_id', sa.Integer(), nullable=False), | ||
sa.Column('instrument', sa.Text(), nullable=False), | ||
sa.Column('research_study_id', sa.Integer(), nullable=False), | ||
sa.Column('authored', sa.DateTime(), nullable=False), | ||
sa.Column('data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), | ||
sa.ForeignKeyConstraint(['subject_id'], ['users.id'], ), | ||
sa.ForeignKeyConstraint( | ||
['questionnaire_response_id'], ['questionnaire_responses.id'], ), | ||
sa.PrimaryKeyConstraint('id'), | ||
) | ||
|
||
op.create_index( | ||
op.f('ix_research_data_authored'), 'research_data', ['authored'], unique=False) | ||
op.create_index( | ||
op.f('ix_research_data_instrument'), 'research_data', ['instrument'], unique=False) | ||
op.create_index( | ||
op.f('ix_research_data_subject_id'), 'research_data', ['subject_id'], unique=False) | ||
op.create_index( | ||
op.f('ix_research_data_questionnaire_response_id'), | ||
'research_data', ['questionnaire_response_id'], unique=True) | ||
op.create_index( | ||
op.f('ix_research_data_research_study_id'), | ||
'research_data', ['research_study_id'], unique=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f('ix_research_data_research_study_id'), table_name='research_data') | ||
op.drop_index(op.f('ix_research_data_questionnaire_response_id'), table_name='research_data') | ||
op.drop_index(op.f('ix_research_data_subject_id'), table_name='research_data') | ||
op.drop_index(op.f('ix_research_data_instrument'), table_name='research_data') | ||
op.drop_index(op.f('ix_research_data_authored'), table_name='research_data') | ||
op.drop_table('research_data') | ||
# ### end Alembic commands ### |
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
Oops, something went wrong.