合并更新

This commit is contained in:
2024-12-06 13:48:05 +08:00
parent 33d0a96ef7
commit c8a01cdf7e

View File

@@ -20,8 +20,6 @@ export async function update(table, rank, views) {
await conn.query(`INSERT INTO temp_updates (id, views_count) VALUES ?`, [values])
}
for (let name of ['comment', 'praise', 'collect']) {
console.log(`统计当天时间段内 ${name} 数到临时表`)
await conn.query(`
@@ -52,11 +50,8 @@ export async function update(table, rank, views) {
views_count * 25;
`)
console.log('更新前清空当日记录')
await conn.query(`UPDATE ${table} SET ${rank} = 0`)
console.log('更新数据从临时表转入生产库')
await conn.query(`UPDATE ${table} t JOIN temp_updates tu ON t.id = tu.id SET t.${rank} = tu.${rank}`)
await conn.query(`UPDATE ${table} t LEFT JOIN temp_updates tu ON t.id = tu.id SET t.${rank} = IFNULL(tu.${rank}, 0)`)
await conn.end()
console.log('更新完成')
}