Skip to content

Normalize ranking persistence and migrate existing stores - #80

Draft
hubab1 wants to merge 1 commit into
mainfrom
codex/v6-normalized-ranking
Draft

Normalize ranking persistence and migrate existing stores#80
hubab1 wants to merge 1 commit into
mainfrom
codex/v6-normalized-ranking

Conversation

@hubab1

@hubab1 hubab1 commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Introduce the V6 normalized ranking schema for crawls, ranking facts, deduplicated app revisions, tracked-history links, and resumable migration state.
  • Refactor ranking refresh, history, keyword tables, research, insights, suggestions, and MCP reads to query normalized facts directly.
  • Preserve existing tracked history with recovery crawls when a tracked result differs from its canonical crawl.
  • Stop producing redundant AppKeywordStats ranking data while preserving all existing rows.

Why

Ranking pages and app metadata were persisted repeatedly under canonical crawls and tracked daily snapshots. That duplication grew a real production store beyond 2 GB and made relationship loading and mutation unnecessarily expensive.

The migration removes duplicate storage without reducing the amount of tracked information. Legacy ranking tables are deleted only after exact fact-by-fact validation succeeds.

Migration safety

  • Uses a lightweight SwiftData V5 → V6 schema migration followed by a resumable, batched application migration.
  • Uses stable numeric offsets so mixed ASCII, accented, and CJK observation keys migrate consistently.
  • Preserves all 1,373,792 canonical ranking facts and 7,825 tracked daily snapshots from the production-copy fixture.
  • Adds 1,457 recovery crawls containing 7,533 facts where tracked history differs from canonical data.
  • Preserves all 177,604 existing AppKeywordStats rows.
  • Deletes 1,099,177 redundant tracked-result rows only after exact validation.

Measured impact

The production database used for validation contained 7,491 crawls and 1,373,792 canonical ranking facts.

  • Logical SQLite usage: 2.17 GB → 1.30 GB (40.1% reduction).
  • Migration trial 1: 17m 24s, 348 MiB peak RSS.
  • Migration trial 2: 18m 11s, 351 MiB peak RSS.
  • Both trials started from a freshly copied, closed production store and produced identical final counts.
  • The original production store remained unmigrated and unchanged.

Validation

  • 670/670 tests passed across 58 suites.
  • Added migration coverage for resumability, rollback/validation behavior, tracked recovery crawls, exact counts, and mixed-Unicode multi-batch ordering.
  • PRAGMA quick_check: ok after both production-copy migrations.
  • Rebuilt app launched against the migrated store and rendered the real 338-keyword tracked-app table, rankings, movement, distribution, and trend summaries.
  • Clean idle CPU measured at 0%.
  • git diff --check passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant