From c8a01cdf7ecdcad2e8d230e90d37c1b0e583539f Mon Sep 17 00:00:00 2001 From: satori Date: Fri, 6 Dec 2024 13:48:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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('更新完成') }