clear_dangling_timestamps.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env node
  2. // Clear timestamps which don't have any corresponding history ops
  3. // usage: scripts/flush_all.js <limit>
  4. import logger from '@overleaf/logger'
  5. import * as RedisManager from '../app/js/RedisManager.js'
  6. const argv = process.argv.slice(2)
  7. const limit = parseInt(argv[0], 10) || null
  8. // find all dangling timestamps and clear them
  9. async function main() {
  10. logger.info(
  11. { limit },
  12. 'running redis scan for project timestamps, this may take a while'
  13. )
  14. const projectIdsWithFirstOpTimestamps =
  15. await RedisManager.promises.getProjectIdsWithFirstOpTimestamps(limit)
  16. const totalTimestamps = projectIdsWithFirstOpTimestamps.length
  17. logger.info(
  18. { totalTimestamps },
  19. 'scan completed, now clearing dangling timestamps'
  20. )
  21. let clearedTimestamps = 0
  22. let processed = 0
  23. for (const projectId of projectIdsWithFirstOpTimestamps) {
  24. const result = await RedisManager.promises.clearDanglingFirstOpTimestamp(
  25. projectId
  26. )
  27. processed++
  28. clearedTimestamps += result
  29. if (processed % 1000 === 0) {
  30. logger.info(
  31. { processed, totalTimestamps, clearedTimestamps },
  32. 'clearing timestamps'
  33. )
  34. }
  35. }
  36. logger.info({ processed, totalTimestamps, clearedTimestamps }, 'completed')
  37. process.exit(0)
  38. }
  39. main()