Repository navigation
fix(contests,sync): prune obsolete scheduled contests and enforce unique externalId index in DsaContest - #332
Conversation
…que externalId index in DsaContest Signed-off-by: Trunal Patil <patiltrunal06@gmail.com>
|
Hi @Trunal2005, Following the recent merge of PR #320 into \main, this pull request currently has a merge conflict in:
Could you please sync your branch with \main\ and resolve the conflict? \\�ash Resolve the conflict in backend/src/db/models/dsaContest.model.ts and verify tests passgit push origin fix/issue-328-contest-sync-pruning Once the conflict is resolved and CI passes, we will proceed with the review and merge. Thank you! |
|
Hi @VarshithReddy2006 👋 Thank you for the update! I am checking the merge conflict in |
|
Resolved \dsaContest.model.ts\ indexes merge conflict against main and squash-merged! Thanks @Trunal2005. |
Description
Fixes #328
In
backend/src/modules/platform-sync/contests/contestRefresh.service.tsandbackend/src/db/models/dsaContest.model.ts:refreshPlatformContests, only active incoming contests were upserted intoDsaContest. If a future scheduled contest was cancelled, rescheduled, or removed by upstream providers (Codeforces, LeetCode, AtCoder, CodeChef), it remained in MongoDB indefinitely and was returned as a phantom scheduled contest in fallback/database queries.dsaContest.model.ts, the index{ platform: 1, externalId: 1, kind: 1 }lacked theunique: trueconstraint. Under concurrent worker runs ofrefreshPlatformContests, parallel upsert calls could produce duplicate documents with identical(platform, externalId, kind).Key Changes
{ unique: true, partialFilterExpression: { kind: 'scheduled', externalId: { $type: 'string' } } }to{ platform: 1, externalId: 1, kind: 1 }inDsaContest. This enforces strict uniqueness across scheduled contests while accommodating non-scheduled documents.refreshPlatformContests, all scheduled contests for that platform withendTime >= nowwhoseexternalIdis not present in the newly fetched batch are automatically pruned viaDsaContest.deleteMany.(platform, externalId, kind)is rejected by the unique compound index.Verification
npm test --prefix backend -- src/__tests__/modules/platform-sync/contest-sources.test.ts --run(15/15 tests passed)node scripts/verify-dco.js --range upstream/main..HEAD(DCO signed-off)Please add the labels nsoc26, level3, bug to both the issue (#328) and this PR.