overleaf/services/project-history/scripts/clear_dangling_timestamps.js
Alf Eaton 6cc2db3cdd Merge pull request #17525 from overleaf/ae-upgrade-prettier
Upgrade Prettier to v3

GitOrigin-RevId: 6f1338f196408f3edb4892d5220ad3665ff1a5bc
2024-03-26 09:04:05 +00:00

43 lines
1.2 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()