diff --git a/update.js b/update.js index 7ec8d0a..92e34d2 100644 --- a/update.js +++ b/update.js @@ -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('更新完成') }