Skip to content

fix(api): keep the stored guildId when saving a player - #1006

Open
ugcodrr wants to merge 11 commits into
fix/nested-savesfrom
fix/player-guild-id-race
Open

ugcodrr wants to merge 11 commits into
fix/nested-savesfrom
fix/player-guild-id-race

Conversation

@ugcodrr

@ugcodrr ugcodrr commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Description: A player save wrote back the guildId it read before waiting on Hypixel, so a guild refresh that landed in between got undone.

  1. Players and sessions saved from now on have no __v, since the Player schema turns the version key off.

Merge order for the perf PRs is in #1002.

Testing: save a player and a session here and on #1005. The stored documents only differ by the missing __v.

Depends on #1005

A player save replaced the whole document, guildId included, with what it
read before waiting on Hypixel. A guild refresh that set or unset the
player's guildId in that window was overwritten, and later refreshes reuse
the cached member's guildId, so it could stay wrong for up to a day.

- Save with one pipeline update: the document replaceOne would store, with
  the guildId that's stored when the write lands. Only guild refreshes
  write guildId now
- Keep the __v: 0 that Mongoose's replaceOne adds to every replacement, so
  stored documents don't change
- Run apps/api's in-source tests, for a snapshot of the update
@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
statsify Ignored Ignored Nov 5, 2026 8:18am UTC

Mongoose's replaceOne added __v: 0 to every player it saved, and the
guildId-keeping update hard-coded it to match. Nothing reads __v, so the
Player schema now turns the version key off and the update leaves it out.
Players saved from now on have no __v; existing ones keep theirs until
their next save.

Session extends Player and would inherit the setting, so the session
model turns its version key back on and session documents don't change.
Guilds have their own schema and don't change either.
Session extends Player and inherits its schema options, so it now has no
version key either. Session resets from now on store no __v; existing
sessions keep theirs until they're reset. Nothing reads it.
@vercel

vercel Bot commented Nov 3, 2026

Copy link
Copy Markdown

Deployment failed for project statsify with the following error:

Resource is limited - try again in 1 day (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/statsify-net?upgradeToPro=build-rate-limit

This branch was previously deployed

1 inactive (outdated) deployment
Preview — 849d2346 Deployed Oct 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant