Upcoming papers sync can run twice at once and duplicate or empty the list

未关闭
#556 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@Dx-Alz-xD 已经在做这个了。

开始于 2026年11月11日。

  • #563 来自 @Dx-Alz-xD —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
mongodb, typescript
领域
backend, databases

调研方向

Read src/lib/services/upcoming-sync.ts, especially the date check and the deleteMany/insertMany sequence. The issue suggests claiming the day atomically and replacing subjects transactionally or with a bulk write; first check the open pull request #563 to understand work already underway. Done means concurrent requests cannot duplicate subjects or serve an empty list during the sync.

由索引模型根据 Issue 内容生成。

描述

Describe the bug
checkAndSyncUpcomingSlots runs on the first /api/upcoming-papers request after the daily cutoff, it reads lastSyncedDate rebuilds the list and then does deleteMany({}) followed by insertMany(...), redudant

https://github.com/CodeChefVIT/papers-codechef/blob/6e3aa1152a34c7eb46d36f58294dffd9ff3b3c7b/src/lib/services/upcoming-sync.ts#L31
https://github.com/CodeChefVIT/papers-codechef/blob/6e3aa1152a34c7eb46d36f58294dffd9ff3b3c7b/src/lib/services/upcoming-sync.ts#L89-L103

Nothing stops two requests that arrive together from both seeing the old date and both running the sync, then:

  • both delete and both insert, so every upcoming subject can appear twice or
  • a request served between one syncs delete and its insert sees an empty list and gets a 404

To Reproduce
hard to hit by hand, Send several requests to /api/upcoming-papers at the same moment just after the cutoff on a day that hasnt synced yet, then check the upcomingsubjects collection for duplicates

Expected behavior
Only one request should run the sync. eg: claim the day atomically first with findOneAndUpdate({ lastSyncedDate: { $ne: today } }, { $set: { lastSyncedDate: today } }) and only sync if that update matched then replace the subjects in a transaction or with a bulk write

主要语言
TypeScript
星标
23
派生
67
平均合并
2 天 17 小时
30 天内合并 PR
7

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

CodeChefVIT/papers-codechef 的其他 Issue

查看 CodeChefVIT/papers-codechef 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。