HistoryRedisManager.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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('@overleaf/redis-wrapper').createClient(
  16. Settings.redis.history
  17. )
  18. const Keys = Settings.redis.history.key_schema
  19. const logger = require('@overleaf/logger')
  20. module.exports = HistoryRedisManager = {
  21. recordDocHasHistoryOps(project_id, doc_id, ops, callback) {
  22. if (ops == null) {
  23. ops = []
  24. }
  25. if (callback == null) {
  26. callback = function () {}
  27. }
  28. if (ops.length === 0) {
  29. 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
  30. }
  31. logger.debug(
  32. { project_id, doc_id },
  33. 'marking doc in project for history ops'
  34. )
  35. return rclient.sadd(
  36. Keys.docsWithHistoryOps({ project_id }),
  37. doc_id,
  38. function (error) {
  39. if (error != null) {
  40. return callback(error)
  41. }
  42. return callback()
  43. }
  44. )
  45. },
  46. }