fix: real root cause - ORDER BY id forced a full table scan every batch, use received_at (indexed) instead
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user