Commit Graph

3 Commits

Author SHA1 Message Date
freemo 1d18aa80ca fix(database): replace type: ignore with assert for type narrowing in LegacyDataMigrator
Remove the unsafe `# type: ignore` suppression on line 111 of
`legacy_migrator.py` and replace it with an explicit
`assert existing_plan.id is not None` statement. This provides
proper type narrowing to the type checker while preserving the
logical correctness guaranteed by the preceding `if existing_plan:`
guard.

Also adds a new BDD scenario in `legacy_migrator_coverage.feature`
that explicitly exercises the code path where an existing plan with
a non-None id is found during migration, verifying the assert-based
type narrowing works correctly end-to-end.

ISSUES CLOSED: #3051
2026-05-30 10:38:39 -04:00
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
freemo d3fb2f9a74 feat: continued with phase 2 adding database migration scripts to the mix 2025-11-13 18:25:24 -05:00