Repository navigation
Store finished games and show the most popular moves - #3
Merged
Merged
Conversation
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Contributor
There was a problem hiding this comment.
Devin Review found 4 findings. Devin automatically fixed all 4 findings.
Fixed by Devin (4)
- Missing archives for mobile games — Submission moved out of the panel into a store subscription (archiveWatcher) started in App, so it runs on every layout and view.
- Incorrect finished-game deduplication — Games are sent only on the transition from a running game to its finished continuation, so neither remounts nor same-shaped restarts affect dedup.
- Merged Random Chess explorer positions — positionHash appends the rolled kinds' names in board order when any rolled piece is on the board.
- Variant totals frozen across completed games — Summary and explorer refetch whenever a game is stored; edge cache removed.
Contributor
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.
Summary
Adds a server-side archive of finished games so the site can report the most popular moves, results and endings per variant. It uses a new SQLite-backed Durable Object (
GameArchive, one global instance, migrationv2), not PostHog: the data lives next to the existingGameRoomand needs no new account or secret.Ingestion
GameRoom.archive()runs when a game ends by a move, a resignation or a timeout, and sends the entry straight to the archive.watchFinishedGames()(src/lib/archiveWatcher.ts, started inApp) is a store subscription. It fires only on the step from a running game to its finished continuation, so reloads, view switches and finished games opened from a link are never sent. It postsPOST /api/archivewith{ variant, moves: MoveRequest[], ending, source }. The Worker replays every move fromcreateInitialState(variant)throughresolveMove(the legality check pulled out ofGameRoomintosrc/lib/replay.ts, so both paths use the same rules). It keeps the game only if the moves end it, or if the client saysresign/timeoutand the moves left the game open. Each IP can post 20 games per 10 minutes.goonchess:share-games).Storage (
worker/archive.ts)games: one row per game (variant key, source, winner index, status, SAN moves).variants: running totals per variant.position_moves:(variant_key, position, move)→ games, wins, draws, for the first 24 plies (EXPLORER_DEPTH).variantKey= sha256 ofpackVariant(variant)with no random seed.positionHash= sha256 ofpositionKey(state), plus the kinds of any rolled Random Chess pieces.Read API:
no-store. The panel refetches whenever this page stores a game.GET /api/stats/moves?variant=&position=GET /api/stats/summary?variant=GET /api/stats/summaryOther changes
BOARD_LIGHT/BOARD_DARKmoved tosrc/lib/boardShades.ts, so the Worker can importvariantCodecwithout DOM types.allowCreateis now built from a genericrateLimiter.Testing
npx tsgo -b,npm test(new tests insrc/lib/archive.test.ts),oxlintandnpm run buildall pass, andwrangler deploy --dry-runshows theARCHIVEbinding.wrangler devsmoke test: posted Fool's Mate twice, then read/api/stats/movesand/api/stats/summary, which returned the expected counts. A truncated, unfinished game was rejected withnot_finished.Implemented in session Add game storage backend with move analytics
Review with Devin · Open in Devin Desktop