HistoryRedisManager.js 1.4 KB

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