Two related nits from the ultrareview of PR #145/#147 (issue #138's country/continent work), not fixed yet since they're efficiency/maintainability, not correctness:
1. Redundant full-table reads per snapshot cycle
snapshotManager.js's takeSnapshot() now calls getDecentralizationStats(), getFullDatacenterBreakdown(), getFullCountryBreakdown(), and getFullContinentBreakdown() -- each of which independently calls getAllNodeIpClassifications() (decentralizationService.js), which fully paginates the whole node_ip_classification table under Supabase. That's up to 4 full-table reads of the same data, once per snapshot cycle, in every environment.
Fix direction: one shared fetch of allClassifications + candidateIps in snapshotManager.js (or a single computeAllBreakdowns() helper in decentralizationService.js), then three in-memory group-bys instead of three separate DB round-trips.
2. Country/continent logic duplicated across 4 files
Country and continent are handled by near-identical parallel copies in:
decentralizationService.js: getFullCountryBreakdown() / getFullContinentBreakdown() (differ only by field name)
sqliteAdapter.js: createDecentralizationCountrySnapshots/getDecentralizationCountrySnapshotHistory and their continent twins
supabaseAdapter.js: the same 4 functions
snapshotManager.js: two near-identical try/catch blocks (fetch + write) for country vs. continent
Adding a third dimension (e.g. ASN, region) currently means editing all four modules, and every future bugfix has to be applied twice.
Fix direction: a single set of functions parameterized by dimension (name field, code field, table name) -- analogous to how getFullDatacenterBreakdown() already handles one dimension alone -- would remove roughly 150 duplicated lines and make future dimensions a one-file change.
Scope
src/lib/services/decentralizationService.js
src/lib/db/adapters/sqliteAdapter.js / supabaseAdapter.js
src/lib/db/snapshotManager.js
Out of scope
No behavior change intended -- this is a pure refactor. Any change here needs the existing decentralization test suite (decentralizationService.test.js, nodeIpClassification.test.js, snapshotManager.test.js, decentralizationSnapshots.test.js) to keep passing unmodified in outcome, even if the internals move.
Two related nits from the ultrareview of PR #145/#147 (issue #138's country/continent work), not fixed yet since they're efficiency/maintainability, not correctness:
1. Redundant full-table reads per snapshot cycle
snapshotManager.js'stakeSnapshot()now callsgetDecentralizationStats(),getFullDatacenterBreakdown(),getFullCountryBreakdown(), andgetFullContinentBreakdown()-- each of which independently callsgetAllNodeIpClassifications()(decentralizationService.js), which fully paginates the wholenode_ip_classificationtable under Supabase. That's up to 4 full-table reads of the same data, once per snapshot cycle, in every environment.Fix direction: one shared fetch of
allClassifications+candidateIpsinsnapshotManager.js(or a singlecomputeAllBreakdowns()helper indecentralizationService.js), then three in-memory group-bys instead of three separate DB round-trips.2. Country/continent logic duplicated across 4 files
Country and continent are handled by near-identical parallel copies in:
decentralizationService.js:getFullCountryBreakdown()/getFullContinentBreakdown()(differ only by field name)sqliteAdapter.js:createDecentralizationCountrySnapshots/getDecentralizationCountrySnapshotHistoryand their continent twinssupabaseAdapter.js: the same 4 functionssnapshotManager.js: two near-identical try/catch blocks (fetch + write) for country vs. continentAdding a third dimension (e.g. ASN, region) currently means editing all four modules, and every future bugfix has to be applied twice.
Fix direction: a single set of functions parameterized by dimension (name field, code field, table name) -- analogous to how
getFullDatacenterBreakdown()already handles one dimension alone -- would remove roughly 150 duplicated lines and make future dimensions a one-file change.Scope
src/lib/services/decentralizationService.jssrc/lib/db/adapters/sqliteAdapter.js/supabaseAdapter.jssrc/lib/db/snapshotManager.jsOut of scope
No behavior change intended -- this is a pure refactor. Any change here needs the existing decentralization test suite (
decentralizationService.test.js,nodeIpClassification.test.js,snapshotManager.test.js,decentralizationSnapshots.test.js) to keep passing unmodified in outcome, even if the internals move.