fix(database): move get_all_for_project call outside loop in LegacyDataMigrator #3249

Merged
freemo merged 1 commits from fix/legacy-migrator-inefficient-get-all-for-project into master 2026-04-05 21:08:52 +00:00

1 Commits

Author SHA1 Message Date
freemo e1f5c95bad fix(database): move get_all_for_project call outside loop in LegacyDataMigrator
CI / lint (pull_request) Successful in 26s
CI / typecheck (pull_request) Successful in 51s
CI / security (pull_request) Successful in 58s
CI / quality (pull_request) Successful in 34s
CI / build (pull_request) Successful in 17s
CI / helm (pull_request) Successful in 22s
CI / unit_tests (pull_request) Successful in 6m48s
CI / e2e_tests (pull_request) Successful in 15m40s
CI / integration_tests (pull_request) Successful in 22m59s
CI / coverage (pull_request) Successful in 10m59s
CI / docker (pull_request) Successful in 1m24s
CI / status-check (pull_request) Successful in 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 58m1s
Move ctx.plans.get_all_for_project(project.id) outside the plan
iteration loop in LegacyDataMigrator.migrate_project_data to eliminate
an N+1 database query pattern.

Previously, the method fetched all plans from the database on every
iteration of the plans loop, resulting in O(N) queries where N is the
number of plans in the legacy plans.json file. For projects with many
plans, this caused significant unnecessary database load during migration.

The fix fetches all existing plans once before the loop begins, then
uses the in-memory list for duplicate detection on each iteration.

Also verified no other similar N+1 patterns exist in LegacyDataMigrator.

Added a new Behave scenario 'get_all_for_project is called only once for
multiple plans' that patches the repository method to count invocations
and asserts exactly one call regardless of how many plans are migrated.

ISSUES CLOSED: #3047
2026-04-05 08:26:50 +00:00