overleaf/services/project-history/scripts/clear_dangling_timestamps.js
Alf Eaton ee85d948e2 Avoid duplicating a math-closing dollar sign (#11227)
GitOrigin-RevId: ef2ef77e26df59d1af3df6dc664e284d3c70102d
2023-01-16 08:41:42 +00:00

44 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
// Clear timestamps which don't have any corresponding history ops
// usage: scripts/flush_all.js <limit>
import logger from '@overleaf/logger'
import * as RedisManager from '../app/js/RedisManager.js'
const argv = process.argv.slice(2)
const limit = parseInt(argv[0], 10) || null
// find all dangling timestamps and clear them
async function main() {
logger.info(
{ limit },
'running redis scan for project timestamps, this may take a while'
)
const projectIdsWithFirstOpTimestamps =
await RedisManager.promises.getProjectIdsWithFirstOpTimestamps(limit)
const totalTimestamps = projectIdsWithFirstOpTimestamps.length
logger.info(
{ totalTimestamps },
'scan completed, now clearing dangling timestamps'
)
let clearedTimestamps = 0
let processed = 0
for (const projectId of projectIdsWithFirstOpTimestamps) {
const result = await RedisManager.promises.clearDanglingFirstOpTimestamp(
projectId
)
processed++
clearedTimestamps += result
if (processed % 1000 === 0) {
logger.info(
{ processed, totalTimestamps, clearedTimestamps },
'clearing timestamps'
)
}
}
logger.info({ processed, totalTimestamps, clearedTimestamps }, 'completed')
process.exit(0)
}
main()