HistoryRedisManager.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* eslint-disable
  2. camelcase,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. let HistoryRedisManager
  14. const Settings = require('@overleaf/settings')
  15. const { rclient } = require('./RedisManager') // docsWithHistoryOps lives in main redis
  16. const Keys = Settings.redis.history.key_schema
  17. const logger = require('@overleaf/logger')
  18. module.exports = HistoryRedisManager = {
  19. recordDocHasHistoryOps(project_id, doc_id, ops, callback) {
  20. if (ops == null) {
  21. ops = []
  22. }
  23. if (callback == null) {
  24. callback = function () {}
  25. }
  26. if (ops.length === 0) {
  27. return callback(new Error('cannot push no ops')) // This should never be called with no ops, but protect against a redis error if we sent an empty array to rpush
  28. }
  29. logger.debug(
  30. { project_id, doc_id },
  31. 'marking doc in project for history ops'
  32. )
  33. return rclient.sadd(
  34. Keys.docsWithHistoryOps({ project_id }),
  35. doc_id,
  36. function (error) {
  37. if (error != null) {
  38. return callback(error)
  39. }
  40. return callback()
  41. }
  42. )
  43. },
  44. }