diff --git a/server/src/index.js b/server/src/index.js index b802fbf..ea81541 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -234,7 +234,9 @@ function grantQuota(openid, data) { // 首页查询:返回余额和「哪几个人的提醒有风险」 function getQuotaStatus(openid) { const balance = quota.getBalance(openid) - const rows = db.prepare('SELECT * FROM anniversaries WHERE openid = ? AND remindEnabled = 1').all(openid) + // ORDER BY id 必须与 reminder.js 的取数保持一致:平局(同日、同 kind、同 importance)时 + // 先后顺序完全由这里决定,两边不一致就会出现「预告的人名不是真正被跳过的人」 + const rows = db.prepare('SELECT * FROM anniversaries WHERE openid = ? AND remindEnabled = 1 ORDER BY id').all(openid) const { atRiskCount, atRiskNames } = atRisk.computeAtRisk(rows.map(normalize), balance) return { success: true, balance, atRiskCount, atRiskNames } } diff --git a/server/src/reminder.js b/server/src/reminder.js index b72d219..57e2570 100644 --- a/server/src/reminder.js +++ b/server/src/reminder.js @@ -144,7 +144,11 @@ async function runForUser(openid, items, today = new Date()) { async function runOnce() { console.log('[reminder] 开始扫描纪念日...') - const list = db.prepare('SELECT * FROM anniversaries WHERE remindEnabled = 1').all() + // ORDER BY id 不是为了排序好看,而是为了「平局可复现」: + // 同一天、同 kind、同 importance 的条目在 sort 里比不出先后(JS sort 是稳定的), + // 最终取舍就取决于 SQLite 的返回顺序。这里和 index.js 的 getQuotaStatus 必须用同一个 + // 兜底顺序,否则首页预告「谁有风险」的人名会和实际被跳过的人对不上。 + const list = db.prepare('SELECT * FROM anniversaries WHERE remindEnabled = 1 ORDER BY id').all() console.log(`[reminder] 启用提醒的纪念日 ${list.length} 条`) // 额度是按用户算的,所以必须分组处理