HistoryRedisManager.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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('logger-sharelatex')
  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.log({ project_id, doc_id }, 'marking doc in project for history ops')
  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. }