/api/stats: 単一母集合CTE map_pop を導入して集計ソース混在を解消 - #255
Open
badjoke-lab wants to merge 2 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
/api/statsがstats_cache/ DB-fallback / live 集計を合成する経路になり、同一レスポンス内でtotal_count等とbreakdownが別ソース(別母集合)になり母集合一致が崩れたため修正する。metaを追加する。Description
map_popを導入し、buildMapPopulationCteを使ってWITH map_pop AS (...)を作成して全クエリで参照するようにした(app/api/stats/route.ts)。fetchDbSnapshotV4をmap_pop参照に一本化してtotal_places/total_count/breakdown/verification_breakdown/distinct/ranking/chain/matrix/accepting_any をすべてmap_popから算出し、verification が存在しない場合はunverified = totalを補完する整合チェックを追加した(同ファイル)。loadStatsFromDbの stats_cache / 部分合成経路を撤去してfetchDbSnapshotV4一本に統一し、DB 非稼働時はlimited=true(または JSON fallback)の明示レスポンスのみを返すようにして「別ソース混在」を禁止した(app/api/stats/route.ts)。meta: { limited, population: "map_pop", where_version: "v1", source: "db"|"fallback" }を追加し、フロント側の型 (app/(site)/stats/StatsPageClient.tsx) と監査ドキュメント(docs/audits/stats-v4.0-parity.audit.md/docs/stats-v4.0-parity.checklist.md)を更新した。/api/statsを叩きmeta.population === "map_pop"、meta.where_version === "v1"、total_count === breakdown.owner + breakdown.community + breakdown.directory + breakdown.unverified、およびmeta.sourceがdbまたはfallbackのいずれか単一であることを確認する。Testing
npm run test:statsを実行したが、テスト実行環境でCannot find module '@/lib/db'によるモジュール解決エラーでテストスイートは失敗した(リポジトリの既存テストランナー環境依存のため)。npm run lint(next lint)は実行済みで成功し、型定義・コードフォーマットに致命的な問題はなかった。metaを用いた JSON チェックで行えるようにした。Codex Task