Commit Graph

2 Commits

Author SHA1 Message Date
freemo e1f5c95bad fix(database): move get_all_for_project call outside loop in LegacyDataMigrator
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
freemo d3fb2f9a74 feat: continued with phase 2 adding database migration scripts to the mix 2025-11-13 18:25:24 -05:00