HistoryRedisManager.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* eslint-disable
  2. no-unused-vars,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. let HistoryRedisManager
  13. const Settings = require('@overleaf/settings')
  14. const { rclient } = require('./RedisManager') // docsWithHistoryOps lives in main redis
  15. const Keys = Settings.redis.history.key_schema
  16. const logger = require('@overleaf/logger')
  17. module.exports = HistoryRedisManager = {
  18. recordDocHasHistoryOps(projectId, docId, ops, callback) {
  19. if (ops == null) {
  20. ops = []
  21. }
  22. if (callback == null) {
  23. callback = function () {}
  24. }
  25. if (ops.length === 0) {
  26. 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
  27. }
  28. logger.debug({ projectId, docId }, 'marking doc in project for history ops')
  29. return rclient.sadd(
  30. Keys.docsWithHistoryOps({ project_id: projectId }),
  31. docId,
  32. function (error) {
  33. if (error != null) {
  34. return callback(error)
  35. }
  36. return callback()
  37. }
  38. )
  39. },
  40. }