diff --git a/server.js b/server.js index 387842e..97de9ed 100644 --- a/server.js +++ b/server.js @@ -86,13 +86,13 @@ const stmtSummarizeBatch = DB.prepare(` INSERT INTO daily_summary (day, site_id, bot_type, action, country, count) SELECT strftime('%Y-%m-%d', received_at, 'unixepoch'), site_id, bot_type, action, country, COUNT(*) FROM bots - WHERE id IN (SELECT id FROM bots WHERE received_at < ? ORDER BY id LIMIT ?) + WHERE id IN (SELECT id FROM bots WHERE received_at < ? ORDER BY received_at LIMIT ?) GROUP BY 1, 2, 3, 4, 5 ON CONFLICT (day, site_id, bot_type, action, country) DO UPDATE SET count = count + excluded.count `); const stmtDeleteBatch = DB.prepare( - 'DELETE FROM bots WHERE id IN (SELECT id FROM bots WHERE received_at < ? ORDER BY id LIMIT ?)' + 'DELETE FROM bots WHERE id IN (SELECT id FROM bots WHERE received_at < ? ORDER BY received_at LIMIT ?)' ); function pruneOldRowsBatch(cutoff) {