Fix negative team nbMembers on account closure by slick-daddy · Pull Request #22109 · lichess-org/lila · GitHub
Skip to content

Fix negative team nbMembers on account closure - #22109

Open
slick-daddy wants to merge 2 commits into
lichess-org:masterfrom
slick-daddy:fix-team-nbmembers-7624
Open

slick-daddy wants to merge 2 commits into
lichess-org:masterfrom
slick-daddy:fix-team-nbmembers-7624

Conversation

@slick-daddy

Copy link
Copy Markdown
Contributor

quitAllOnAccountClosure decremented nbMembers for every team in the cached team list, unconditionally and outside the per-team work queue. Any stale cache entry (or a quit/kick racing the closure) decremented a counter without removing a membership, driving nbMembers to -1. It now reads the user's actual memberships from the DB and quits each team through the guarded per-team path, so a counter only drops when a membership doc was really removed. This also covers disabled teams, which the old cache-sourced list missed.

While there, same class of staleness fix: team deletion now invalidates ex-members' team caches and cleans up their requests, deleteNewlyCreatedBy removes orphaned member/request docs instead of leaving them behind, and class-team sync counts removals that actually happened instead of assuming them all succeeded.

@slick-daddy
slick-daddy force-pushed the fix-team-nbmembers-7624 branch 3 times, most recently from eb8334d to abae4c9 Compare October 16, 2026 11:22
@ornicar
ornicar force-pushed the fix-team-nbmembers-7624 branch from abae4c9 to 5b417b2 Compare October 17, 2026 08:16
quitAllOnAccountClosure decremented nbMembers for every cached team, unconditionally and outside the per-team work queue. Stale cache entries or a quit/kick racing the closure decremented counters without removing memberships, driving nbMembers negative. It now quits actual DB memberships through the guarded per-team path (decrement only on real removal), repeating until none is left, and team deletion paths clean up member docs and caches.
@ornicar
ornicar force-pushed the fix-team-nbmembers-7624 branch from 5b417b2 to 4f3faac Compare October 19, 2026 10:31
Comment thread modules/team/src/main/TeamApi.scala Outdated
@slick-daddy
slick-daddy requested a review from ornicar October 19, 2026 12:13
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.

2 participants