HistoryRedisManager.js 1.4 KB

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