Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: LSDV-4695: Add Project relation to Prediction model to improve overall performance #4629

Merged
merged 6 commits into from Aug 22, 2023

Conversation

dredivaris
Copy link
Contributor

@dredivaris dredivaris commented Aug 14, 2023

PR fulfills these requirements

  • Commit message(s) and PR title follows the format [fix|feat|ci|chore|doc]: TICKET-ID: Short description of change made ex. fix: DEV-XXXX: Removed inconsistent code usage causing intermittent errors
  • Tests for the changes have been added/updated (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • Best efforts were made to ensure docs/code are concise and coherent (checked for spelling/grammatical errors, commented out code, debug logs etc.)
  • Self-reviewed and ran all changes on a local instance (for bug fixes/features)

Change has impacts in these area(s)

(check all that apply)

  • Product design
  • Backend (Database)
  • Backend (API)
  • Frontend

Describe the reason for change

Prediction performance in general has not been optimal due to the necessity of querying through the task model whenever needing to filter on project (Prediction -> Task -> Project).

What does this fix?

This PR is the first of a set of 2 PRs. This PR adds migrations to add the a project foreign key field to Prediction as well as a data migration to populate the new field with the correct project for existing Predictions. I've also added changes across the code on Prediction saves / bulk saves etc to ensure any new Predictions added after the migration will store the project properly.

Once the first PR is live, the second PR will introduce changes to queries which use the new project relation rather than querying through task -> project.

The PRs were separated in this way because until all Predictions have been updated with the new project fk, the queries could not be optimized to use the fk.

What feature flags were used to cover this change?

None - and this is by design. I've introduced code changes here on all Prediction save's/bulk saves to save project_id on create. This is necessary because the next PR will introduce query updates that depend on this Prediction.project_id linkage and if its missing on any Predictions, the query will break. I'll use a feature flag on the following PR to test the query changes however.

Does this PR introduce a breaking change?

(check only one)

  • Yes, and covered entirely by feature flag(s)
  • Yes, and covered partially by feature flag(s)
  • No
  • Not sure (briefly explain the situation below)

What level of testing was included in the change?

(check all that apply)

  • e2e
  • integration
  • unit

Which logical domain(s) does this change affect?

Predictions

…ove performance

Also update anywhere in the code where Predictions are created so project is also connected and adds a failsafe in the Predition save method to add a project if it was not added before
@netlify
Copy link

netlify bot commented Aug 14, 2023

Deploy Preview for heartex-docs canceled.

Name Link
🔨 Latest commit 89060fd
🔍 Latest deploy log https://app.netlify.com/sites/heartex-docs/deploys/64dffbf5b4e93300089d5fb8

@netlify
Copy link

netlify bot commented Aug 14, 2023

Deploy Preview for label-studio-docs-new-theme canceled.

Name Link
🔨 Latest commit 89060fd
🔍 Latest deploy log https://app.netlify.com/sites/label-studio-docs-new-theme/deploys/64dffbf54121cb000856990c

@github-actions github-actions bot added the perf label Aug 14, 2023
@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01% ⚠️

Comparison is base (b6b1705) 75.85% compared to head (89060fd) 75.85%.
Report is 15 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4629      +/-   ##
===========================================
- Coverage    75.85%   75.85%   -0.01%     
===========================================
  Files          157      157              
  Lines        12487    12499      +12     
===========================================
+ Hits          9472     9481       +9     
- Misses        3015     3018       +3     

see 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dredivaris dredivaris merged commit 1986ad7 into develop Aug 22, 2023
38 of 39 checks passed
@sentry-io
Copy link

sentry-io bot commented Aug 24, 2023

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ ImportError: cannot import name 'fill_predictions_project' from 'tasks.functions' (/Users/ylim/code/roblox/hum... tasks.migrations.0042_auto_20230810_2304 in <mo... View Issue
  • ‼️ TypeError: fill_predictions_project() missing 1 required positional argument: 'migration_name' tasks.migrations.0042_auto_20230810_2304 in for... View Issue

Did you find this useful? React with a 👍 or 👎

shayantabatabaee pushed a commit to shayantabatabaee/label-studio that referenced this pull request Sep 19, 2023
…overall performance (HumanSignal#4629)

* perf: LSDV-4695: add new project relation to Prediction model to improve performance

Also update anywhere in the code where Predictions are created so project is also connected and adds a failsafe in the Predition save method to add a project if it was not added before

* Add data migration to update predictions with direct fk to their project

* Update to avoid magic number and add reasoning behind size choice

* Convert data migration to async operation

* Revert changes and use existing project to link to prediction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants