Skip to content

Read materialized player boards and accept Warden mode in army links - #66

Merged
MagicTheDev merged 3 commits into
mainfrom
fix/ranking-ingestion-rollover
Sep 17, 2026
Merged

MagicTheDev merged 3 commits into
mainfrom
fix/ranking-ingestion-rollover

Conversation

@MagicTheDev

Copy link
Copy Markdown
Member

Changes

  • Read Town Hall and league boards from SQL materialized snapshots instead of sorting basic_player on every request.
  • Preserve existing endpoint response fields, 500-row cap and clan metadata joins.
  • Accept and preserve Warden mode in canonical army links alongside the Tracking fix.
  • Pin PostgreSQL CI to the companion schema commit containing migration 020.

Dependencies / rollout

Requires ClashKingInc/DevKit#26, then the companion Tracking implementation to populate both views. Deploy this API only after pg_matviews reports both populated. No production deployments, migrations or merges performed.

Validation

  • Full unit suite: 146 files / 1,393 tests passed.
  • Workspace typecheck and lint passed.
  • PostgreSQL public-data integration: 4 tests passed against disposable Goose 001–020, including snapshot staleness until refresh and reordered results afterward.
  • git diff --check passed.

See docs/player-leaderboard-snapshots.md for deployment order and unchanged contracts.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
clashking-api bed5021 Commit Preview URL

Branch Preview URL
Sep 17 2026, 04:25 AM

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-17T04:28:05.286285Z bed5021 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MagicTheDev

Copy link
Copy Markdown
Member Author

Companion writer: ClashKingInc/ClashKingTracking#30; schema: ClashKingInc/DevKit#26. API CI is pinned to the immutable schema commit containing migration 020. Deploy only after Tracking has populated both views.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 298466be0e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

heroes.sort((a, b) => a.id - b.id || a.pet - b.pet
|| (a.equipment.join("_") < b.equipment.join("_") ? -1 : a.equipment.join("_") > b.equipment.join("_") ? 1 : 0))
const parts = heroes.length ? ["h" + heroes.map((hero) => `${hero.id}${hero.pet >= 0 ? `p${hero.pet}` : ""}${hero.equipment.length ? `e${hero.equipment.join("_")}` : ""}`).join("-")] : []
const parts = heroes.length ? ["h" + heroes.map((hero) => `${hero.id}${hero.mode === undefined ? "" : `m${hero.mode}`}${hero.pet >= 0 ? `p${hero.pet}` : ""}${hero.equipment.length ? `e${hero.equipment.join("_")}` : ""}`).join("-")] : []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include mode when ordering hero entries

When an accepted code contains otherwise-identical hero entries that differ only by mode, the comparator returns zero while the newly emitted value includes mode, so input order leaks into the supposedly canonical result: h2m1-h2m0 and h2m0-h2m1 normalize differently. Because the normalized string is used for exact army_family_members.share_code lookups, a reordered equivalent query can incorrectly miss its family; include mode in the comparator or reject duplicate hero IDs.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d70cb6fc6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const order = family === "townhall" ? "p.league_id DESC,p.trophies DESC,p.tag" : "p.trophies DESC,p.tag"
const rows = yield* sql.unsafe<PlayerLeaderboardRow>(`SELECT row_number() OVER (ORDER BY ${order})::integer AS rank,
const table = family === "townhall" ? "player_townhall_leaderboards" : "player_league_leaderboards"
const rows = yield* sql.unsafe<PlayerLeaderboardRow>(`SELECT p.rank,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Cast snapshot ranks back to numbers

PostgreSQL row_number() produces a bigint, which node-postgres returns as a string; the previous query explicitly used ::integer, but selecting p.rank directly removes that conversion. For any nonempty leaderboard, the request-level PlayerLeaderboardResponse encoder therefore receives a string for the required Schema.Number rank and returns UpstreamUnavailable instead of the board. Cast p.rank to an integer here or convert it before constructing the response.

Useful? React with 👍 / 👎.

@MagicTheDev

Copy link
Copy Markdown
Member Author

Base-storage correction added in bed5021: Dashboard, mobile library and bot handlers now read/write inline images and votes on bases. Requires DevKit PR #26 migration 021; the pinned test schema includes it. Public response shapes are unchanged. Drain old base traffic, migrate, deploy this API, then resume; old handlers cannot use the dropped tables. Full 1,393 unit tests, typecheck/lint, 38 script tests and base PostgreSQL suites passed, including concurrent votes and sparse image staging. No production changes performed.

@MagicTheDev
MagicTheDev merged commit fd7d672 into main Sep 17, 2026
6 checks passed
@MagicTheDev
MagicTheDev deleted the fix/ranking-ingestion-rollover branch September 17, 2026 05:03
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