2020-05-06 06:09:15 -04:00
/ * e s l i n t - d i s a b l e
no - unused - vars ,
* /
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
2020-05-06 06:08:21 -04:00
/ *
* decaffeinate suggestions :
* DS102 : Remove unnecessary code created because of implicit returns
* DS207 : Consider shorter variations of null checks
* Full docs : https : //github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
* /
2020-05-06 06:09:33 -04:00
let HistoryRedisManager
2021-07-12 12:47:15 -04:00
const Settings = require ( '@overleaf/settings' )
2022-06-23 04:08:33 -04:00
const { rclient } = require ( './RedisManager' ) // docsWithHistoryOps lives in main redis
2020-05-06 06:09:33 -04:00
const Keys = Settings . redis . history . key _schema
2021-10-06 05:10:28 -04:00
const logger = require ( '@overleaf/logger' )
2017-04-13 12:00:42 -04:00
2020-05-06 06:09:33 -04:00
module . exports = HistoryRedisManager = {
2023-03-21 08:06:13 -04:00
recordDocHasHistoryOps ( projectId , docId , ops , callback ) {
2020-05-06 06:09:33 -04:00
if ( ops == null ) {
ops = [ ]
}
if ( callback == null ) {
2021-10-27 05:49:18 -04:00
callback = function ( ) { }
2020-05-06 06:09:33 -04:00
}
if ( ops . length === 0 ) {
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
}
2023-03-21 08:06:13 -04:00
logger . debug ( { projectId , docId } , 'marking doc in project for history ops' )
2020-05-06 06:09:33 -04:00
return rclient . sadd (
2023-03-21 08:06:13 -04:00
Keys . docsWithHistoryOps ( { project _id : projectId } ) ,
docId ,
2020-05-06 06:09:33 -04:00
function ( error ) {
if ( error != null ) {
return callback ( error )
}
return callback ( )
}
)
2021-07-13 07:04:42 -04:00
} ,
2020-05-06 06:09:33 -04:00
}