Skip to content

Perf/citations memoize classification - #375

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
Sam-syntax35:perf/citations-memoize-classification
Jul 8, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
Sam-syntax35:perf/citations-memoize-classification

Conversation

@Sam-syntax35

Copy link
Copy Markdown
Contributor

Summary

Memoize expensive domain and article type classification during citations aggregation.

Changes

  • Cache classifyDomain() results by host in getCitationsOverview()
  • Cache classifyArticleType() results by URL + title in getCitationsOverview()
  • Cache classifyDomain() results by host in getCitationGaps()

Why

Previously, repeated hosts and URLs were classified on every citation occurrence. This change memoizes classification results for the duration of each aggregation call, reducing repeated work while preserving identical behavior.

Testing

  • Verified the project builds successfully.
  • Verified Citations overview and Competitor Gaps continue to behave as expected.
  • No database or schema changes.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The citations classification memoization is exactly right — per-call domainClassificationCache (by host) + articleTypeCache (by url\ntitle), looked up before calling classifyDomain / classifyArticleType, in both getCitationsOverview and getCitationGaps. Behavior-preserving (classifyCtx is constant per call, and a cached null is distinguished from a miss via === undefined). I verified typecheck + Prettier in a worktree — both pass. 🎉

Heads-up (harmless): this branch was cut from your #348 branch, so the diff also shows the formatCompactNumber files — but those are byte-identical to main now that #370 merged, so the net change vs main is only citations.ts. A squash-merge will produce a clean citations-only commit. (If you'd rather have a tidy diff, a quick rebase onto main would drop the format files — totally optional.)

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.

2 participants