clear_dangling_timestamps.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 =
  25. await RedisManager.promises.clearDanglingFirstOpTimestamp(projectId)
  26. processed++
  27. clearedTimestamps += result
  28. if (processed % 1000 === 0) {
  29. logger.info(
  30. { processed, totalTimestamps, clearedTimestamps },
  31. 'clearing timestamps'
  32. )
  33. }
  34. }
  35. logger.info({ processed, totalTimestamps, clearedTimestamps }, 'completed')
  36. process.exit(0)
  37. }
  38. main()