[misc] run format_fix and lint:fix

This commit is contained in:
Jakob Ackermann 2021-07-13 12:04:43 +01:00
parent 1e577e24b1
commit 9178394dd6
48 changed files with 1742 additions and 1718 deletions

View file

@ -16,7 +16,7 @@ if ((Settings.sentry != null ? Settings.sentry.dsn : undefined) != null) {
} }
// log updates as truncated strings // log updates as truncated strings
const truncateFn = (updates) => const truncateFn = updates =>
JSON.parse( JSON.parse(
JSON.stringify(updates, function (key, value) { JSON.stringify(updates, function (key, value) {
let len let len
@ -35,7 +35,7 @@ TrackChangesLogger.addSerializers({
rawUpdate: truncateFn, rawUpdate: truncateFn,
rawUpdates: truncateFn, rawUpdates: truncateFn,
newUpdates: truncateFn, newUpdates: truncateFn,
lastUpdate: truncateFn lastUpdate: truncateFn,
}) })
const Path = require('path') const Path = require('path')
@ -91,7 +91,7 @@ app.post('/pack', function (req, res, next) {
[ [
req.query.limit || 1000, req.query.limit || 1000,
req.query.delay || 1000, req.query.delay || 1000,
req.query.timeout || 30 * 60 * 1000 req.query.timeout || 30 * 60 * 1000,
] ]
) )
packWorker.on('exit', function (code, signal) { packWorker.on('exit', function (code, signal) {
@ -120,12 +120,12 @@ app.use(function (error, req, res, next) {
const port = const port =
__guard__( __guard__(
Settings.internal != null ? Settings.internal.trackchanges : undefined, Settings.internal != null ? Settings.internal.trackchanges : undefined,
(x) => x.port x => x.port
) || 3015 ) || 3015
const host = const host =
__guard__( __guard__(
Settings.internal != null ? Settings.internal.trackchanges : undefined, Settings.internal != null ? Settings.internal.trackchanges : undefined,
(x1) => x1.host x1 => x1.host
) || 'localhost' ) || 'localhost'
if (!module.parent) { if (!module.parent) {
@ -146,7 +146,7 @@ if (!module.parent) {
} }
}) })
}) })
.catch((err) => { .catch(err => {
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.') logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
process.exit(1) process.exit(1)
}) })

View file

@ -162,13 +162,11 @@ module.exports = DiffGenerator = {
if (op.i != null) { if (op.i != null) {
newDiff.push({ newDiff.push({
i: op.i, i: op.i,
meta meta,
}) })
} else if (op.d != null) { } else if (op.d != null) {
;({ ;({ consumedDiff, remainingDiff } =
consumedDiff, DiffGenerator._consumeDiffAffectedByDeleteOp(remainingDiff, op, meta))
remainingDiff
} = DiffGenerator._consumeDiffAffectedByDeleteOp(remainingDiff, op, meta))
newDiff.push(...Array.from(consumedDiff || [])) newDiff.push(...Array.from(consumedDiff || []))
} }
@ -211,7 +209,7 @@ module.exports = DiffGenerator = {
return { return {
consumedDiff, consumedDiff,
remainingDiff remainingDiff,
} }
}, },
@ -220,18 +218,15 @@ module.exports = DiffGenerator = {
let remainingOp = deleteOp let remainingOp = deleteOp
while (remainingOp && remainingDiff.length > 0) { while (remainingOp && remainingDiff.length > 0) {
let newPart let newPart
;({ ;({ newPart, remainingDiff, remainingOp } =
newPart, DiffGenerator._consumeDeletedPart(remainingDiff, remainingOp, meta))
remainingDiff,
remainingOp
} = DiffGenerator._consumeDeletedPart(remainingDiff, remainingOp, meta))
if (newPart != null) { if (newPart != null) {
consumedDiff.push(newPart) consumedDiff.push(newPart)
} }
} }
return { return {
consumedDiff, consumedDiff,
remainingDiff remainingDiff,
} }
}, },
@ -262,7 +257,7 @@ module.exports = DiffGenerator = {
if (part.u != null) { if (part.u != null) {
newPart = { newPart = {
d: op.d, d: op.d,
meta meta,
} }
} else if (part.i != null) { } else if (part.i != null) {
newPart = null newPart = null
@ -282,7 +277,7 @@ module.exports = DiffGenerator = {
if (part.u != null) { if (part.u != null) {
newPart = { newPart = {
d: op.d, d: op.d,
meta meta,
} }
} else if (part.i != null) { } else if (part.i != null) {
newPart = null newPart = null
@ -303,7 +298,7 @@ module.exports = DiffGenerator = {
if (part.u) { if (part.u) {
newPart = { newPart = {
d: part.u, d: part.u,
meta meta,
} }
} else if (part.i != null) { } else if (part.i != null) {
newPart = null newPart = null
@ -311,14 +306,14 @@ module.exports = DiffGenerator = {
remainingOp = { remainingOp = {
p: op.p, p: op.p,
d: op.d.slice(DiffGenerator._getLengthOfDiffPart(part)) d: op.d.slice(DiffGenerator._getLengthOfDiffPart(part)),
} }
} }
return { return {
newPart, newPart,
remainingDiff, remainingDiff,
remainingOp remainingOp,
} }
}, },
@ -341,5 +336,5 @@ module.exports = DiffGenerator = {
_getContentOfPart(part) { _getContentOfPart(part) {
return part.u || part.d || part.i || '' return part.u || part.d || part.i || ''
} },
} }

View file

@ -24,11 +24,10 @@ module.exports = DiffManager = {
if (callback == null) { if (callback == null) {
callback = function (error, content, version, updates) {} callback = function (error, content, version, updates) {}
} }
return DocumentUpdaterManager.getDocument(project_id, doc_id, function ( return DocumentUpdaterManager.getDocument(
error, project_id,
content, doc_id,
version function (error, content, version) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -47,7 +46,8 @@ module.exports = DiffManager = {
return callback(null, content, version, updates) return callback(null, content, version, updates)
} }
) )
}) }
)
}, },
getDiff(project_id, doc_id, fromVersion, toVersion, callback) { getDiff(project_id, doc_id, fromVersion, toVersion, callback) {
@ -167,7 +167,7 @@ module.exports = DiffManager = {
{ {
docVersion: version, docVersion: version,
lastUpdateVersion: lastUpdate != null ? lastUpdate.v : undefined, lastUpdateVersion: lastUpdate != null ? lastUpdate.v : undefined,
updateCount: updates.length updateCount: updates.length,
}, },
'rewinding updates' 'rewinding updates'
) )
@ -184,5 +184,5 @@ module.exports = DiffManager = {
return callback(null, startingContent, tryUpdates) return callback(null, startingContent, tryUpdates)
} }
) )
} },
} }

View file

@ -65,8 +65,8 @@ module.exports = DocumentUpdaterManager = {
lines: content.split('\n'), lines: content.split('\n'),
source: 'restore', source: 'restore',
user_id, user_id,
undoing: true undoing: true,
} },
}, },
function (error, res, body) { function (error, res, body) {
if (error != null) { if (error != null) {
@ -86,5 +86,5 @@ module.exports = DocumentUpdaterManager = {
} }
} }
) )
} },
} }

View file

@ -24,7 +24,7 @@ module.exports = {
const url = `http://localhost:${port}/project/${project_id}` const url = `http://localhost:${port}/project/${project_id}`
logger.log({ project_id }, 'running health check') logger.log({ project_id }, 'running health check')
const jobs = [ const jobs = [
(cb) => cb =>
request.get( request.get(
{ url: `http://localhost:${port}/check_lock`, timeout: 3000 }, { url: `http://localhost:${port}/check_lock`, timeout: 3000 },
function (err, res, body) { function (err, res, body) {
@ -41,12 +41,10 @@ module.exports = {
} }
} }
), ),
(cb) => cb =>
request.post({ url: `${url}/flush`, timeout: 10000 }, function ( request.post(
err, { url: `${url}/flush`, timeout: 10000 },
res, function (err, res, body) {
body
) {
if (err != null) { if (err != null) {
logger.err({ err, project_id }, 'error flushing for health check') logger.err({ err, project_id }, 'error flushing for health check')
return cb(err) return cb(err)
@ -55,13 +53,12 @@ module.exports = {
} else { } else {
return cb() return cb()
} }
}), }
(cb) => ),
request.get({ url: `${url}/updates`, timeout: 10000 }, function ( cb =>
err, request.get(
res, { url: `${url}/updates`, timeout: 10000 },
body function (err, res, body) {
) {
if (err != null) { if (err != null) {
logger.err( logger.err(
{ err, project_id }, { err, project_id },
@ -73,12 +70,13 @@ module.exports = {
} else { } else {
return cb() return cb()
} }
}) }
),
] ]
return async.series(jobs, callback) return async.series(jobs, callback)
}, },
checkLock(callback) { checkLock(callback) {
return LockManager.healthCheck(callback) return LockManager.healthCheck(callback)
} },
} }

View file

@ -160,15 +160,18 @@ module.exports = HttpController = {
} }
logger.log({ project_id, doc_id, from, to }, 'getting diff') logger.log({ project_id, doc_id, from, to }, 'getting diff')
return DiffManager.getDiff(project_id, doc_id, from, to, function ( return DiffManager.getDiff(
error, project_id,
diff doc_id,
) { from,
to,
function (error, diff) {
if (error != null) { if (error != null) {
return next(error) return next(error)
} }
return res.json({ diff }) return res.json({ diff })
}) }
)
}, },
getUpdates(req, res, next) { getUpdates(req, res, next) {
@ -194,7 +197,7 @@ module.exports = HttpController = {
} }
return res.json({ return res.json({
updates, updates,
nextBeforeTimestamp nextBeforeTimestamp,
}) })
} }
) )
@ -207,11 +210,9 @@ module.exports = HttpController = {
// Flush updates per pack onto the wire. // Flush updates per pack onto the wire.
const { project_id } = req.params const { project_id } = req.params
logger.log({ project_id }, 'exporting project history') logger.log({ project_id }, 'exporting project history')
UpdatesManager.exportProject(project_id, function ( UpdatesManager.exportProject(
err, project_id,
{ updates, userIds }, function (err, { updates, userIds }, confirmWrite) {
confirmWrite
) {
const abortStreaming = req.aborted || res.finished || res.destroyed const abortStreaming = req.aborted || res.finished || res.destroyed
if (abortStreaming) { if (abortStreaming) {
// Tell the producer to stop emitting data // Tell the producer to stop emitting data
@ -260,7 +261,8 @@ module.exports = HttpController = {
res.addTrailers({ 'X-User-Ids': JSON.stringify(userIds) }) res.addTrailers({ 'X-User-Ids': JSON.stringify(userIds) })
res.end(']') res.end(']')
} }
}) }
)
}, },
restore(req, res, next) { restore(req, res, next) {
@ -334,5 +336,5 @@ module.exports = HttpController = {
return res.sendStatus(200) return res.sendStatus(200)
} }
}) })
} },
} }

View file

@ -43,10 +43,13 @@ module.exports = LockManager = {
callback = function (err, gotLock) {} callback = function (err, gotLock) {}
} }
const lockValue = LockManager.randomLock() const lockValue = LockManager.randomLock()
return rclient.set(key, lockValue, 'EX', this.LOCK_TTL, 'NX', function ( return rclient.set(
err, key,
gotLock lockValue,
) { 'EX',
this.LOCK_TTL,
'NX',
function (err, gotLock) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
@ -55,7 +58,8 @@ module.exports = LockManager = {
} else { } else {
return callback(err, false) return callback(err, false)
} }
}) }
)
}, },
getLock(key, callback) { getLock(key, callback) {
@ -102,10 +106,12 @@ module.exports = LockManager = {
}, },
releaseLock(key, lockValue, callback) { releaseLock(key, lockValue, callback) {
return rclient.eval(LockManager.unlockScript, 1, key, lockValue, function ( return rclient.eval(
err, LockManager.unlockScript,
result 1,
) { key,
lockValue,
function (err, result) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
@ -118,7 +124,8 @@ module.exports = LockManager = {
return callback(new Error('tried to release timed out lock')) return callback(new Error('tried to release timed out lock'))
} }
return callback(err, result) return callback(err, result)
}) }
)
}, },
runWithLock(key, runner, callback) { runWithLock(key, runner, callback) {
@ -129,7 +136,7 @@ module.exports = LockManager = {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return runner((error1) => return runner(error1 =>
LockManager.releaseLock(key, lockValue, function (error2) { LockManager.releaseLock(key, lockValue, function (error2) {
error = error1 || error2 error = error1 || error2
if (error != null) { if (error != null) {
@ -142,7 +149,7 @@ module.exports = LockManager = {
}, },
healthCheck(callback) { healthCheck(callback) {
const action = (releaseLock) => releaseLock() const action = releaseLock => releaseLock()
return LockManager.runWithLock( return LockManager.runWithLock(
`HistoryLock:HealthCheck:host=${HOST}:pid=${PID}:random=${RND}`, `HistoryLock:HealthCheck:host=${HOST}:pid=${PID}:random=${RND}`,
action, action,
@ -153,5 +160,5 @@ module.exports = LockManager = {
close(callback) { close(callback) {
rclient.quit() rclient.quit()
return rclient.once('end', callback) return rclient.once('end', callback)
} },
} }

View file

@ -31,12 +31,12 @@ const createStream = function (streamConstructor, project_id, doc_id, pack_id) {
accessKeyId: settings.trackchanges.s3.key, accessKeyId: settings.trackchanges.s3.key,
secretAccessKey: settings.trackchanges.s3.secret, secretAccessKey: settings.trackchanges.s3.secret,
endpoint: settings.trackchanges.s3.endpoint, endpoint: settings.trackchanges.s3.endpoint,
s3ForcePathStyle: settings.trackchanges.s3.pathStyle s3ForcePathStyle: settings.trackchanges.s3.pathStyle,
} }
return streamConstructor(new AWS.S3(AWS_CONFIG), { return streamConstructor(new AWS.S3(AWS_CONFIG), {
Bucket: settings.trackchanges.stores.doc_history, Bucket: settings.trackchanges.stores.doc_history,
Key: project_id + '/changes-' + doc_id + '/pack-' + pack_id Key: project_id + '/changes-' + doc_id + '/pack-' + pack_id,
}) })
} }
@ -52,7 +52,7 @@ module.exports = MongoAWS = {
const query = { const query = {
_id: ObjectId(pack_id), _id: ObjectId(pack_id),
doc_id: ObjectId(doc_id) doc_id: ObjectId(doc_id),
} }
if (project_id == null) { if (project_id == null) {
@ -92,14 +92,14 @@ module.exports = MongoAWS = {
doc_id, doc_id,
pack_id, pack_id,
origSize: uncompressedData.length, origSize: uncompressedData.length,
newSize: buf.length newSize: buf.length,
}, },
'compressed pack' 'compressed pack'
) )
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
upload.on('error', (err) => callback(err)) upload.on('error', err => callback(err))
upload.on('finish', function () { upload.on('finish', function () {
Metrics.inc('archive-pack') Metrics.inc('archive-pack')
logger.log({ project_id, doc_id, pack_id }, 'upload to s3 completed') logger.log({ project_id, doc_id, pack_id }, 'upload to s3 completed')
@ -135,8 +135,8 @@ module.exports = MongoAWS = {
const download = createStream(S3S.ReadStream, project_id, doc_id, pack_id) const download = createStream(S3S.ReadStream, project_id, doc_id, pack_id)
const inputStream = download const inputStream = download
.on('open', (obj) => 1) .on('open', obj => 1)
.on('error', (err) => callback(err)) .on('error', err => callback(err))
const gunzip = zlib.createGunzip() const gunzip = zlib.createGunzip()
gunzip.setEncoding('utf8') gunzip.setEncoding('utf8')
@ -150,7 +150,7 @@ module.exports = MongoAWS = {
const outputStream = inputStream.pipe(gunzip) const outputStream = inputStream.pipe(gunzip)
const parts = [] const parts = []
outputStream.on('error', (err) => callback(err)) outputStream.on('error', err => callback(err))
outputStream.on('end', function () { outputStream.on('end', function () {
let object let object
logger.log({ project_id, doc_id, pack_id }, 'download from s3 completed') logger.log({ project_id, doc_id, pack_id }, 'download from s3 completed')
@ -169,17 +169,18 @@ module.exports = MongoAWS = {
} }
return callback(null, object) return callback(null, object)
}) })
return outputStream.on('data', (data) => parts.push(data)) return outputStream.on('data', data => parts.push(data))
}, },
unArchivePack(project_id, doc_id, pack_id, callback) { unArchivePack(project_id, doc_id, pack_id, callback) {
if (callback == null) { if (callback == null) {
callback = function (error) {} callback = function (error) {}
} }
return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function ( return MongoAWS.readArchivedPack(
err, project_id,
object doc_id,
) { pack_id,
function (err, object) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
@ -192,6 +193,7 @@ module.exports = MongoAWS = {
object._id = confirmation.insertedId object._id = confirmation.insertedId
callback(null, object) callback(null, object)
}) })
})
} }
)
},
} }

View file

@ -50,10 +50,9 @@ module.exports = MongoManager = {
if (callback == null) { if (callback == null) {
callback = function (error, update, version) {} callback = function (error, update, version) {}
} }
return MongoManager.getLastCompressedUpdate(doc_id, function ( return MongoManager.getLastCompressedUpdate(
error, doc_id,
update function (error, update) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -80,7 +79,9 @@ module.exports = MongoManager = {
return callback(null, update, update.v) return callback(null, update, update.v)
} }
} else { } else {
return PackManager.getLastPackFromIndex(doc_id, function (error, pack) { return PackManager.getLastPackFromIndex(
doc_id,
function (error, pack) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -91,9 +92,11 @@ module.exports = MongoManager = {
return callback(null, null, pack.v_end) return callback(null, null, pack.v_end)
} }
return callback(null, null) return callback(null, null)
})
} }
}) )
}
}
)
}, },
backportProjectId(project_id, doc_id, callback) { backportProjectId(project_id, doc_id, callback) {
@ -103,10 +106,10 @@ module.exports = MongoManager = {
return db.docHistory.updateMany( return db.docHistory.updateMany(
{ {
doc_id: ObjectId(doc_id.toString()), doc_id: ObjectId(doc_id.toString()),
project_id: { $exists: false } project_id: { $exists: false },
}, },
{ {
$set: { project_id: ObjectId(project_id.toString()) } $set: { project_id: ObjectId(project_id.toString()) },
}, },
callback callback
) )
@ -118,7 +121,7 @@ module.exports = MongoManager = {
} }
return db.projectHistoryMetaData.findOne( return db.projectHistoryMetaData.findOne(
{ {
project_id: ObjectId(project_id.toString()) project_id: ObjectId(project_id.toString()),
}, },
callback callback
) )
@ -130,13 +133,13 @@ module.exports = MongoManager = {
} }
return db.projectHistoryMetaData.updateOne( return db.projectHistoryMetaData.updateOne(
{ {
project_id: ObjectId(project_id) project_id: ObjectId(project_id),
}, },
{ {
$set: metadata $set: metadata,
}, },
{ {
upsert: true upsert: true,
}, },
callback callback
) )
@ -151,11 +154,11 @@ module.exports = MongoManager = {
{ {
project_id: ObjectId(project_id), project_id: ObjectId(project_id),
temporary: true, temporary: true,
expiresAt: { $exists: true } expiresAt: { $exists: true },
}, },
{ {
$set: { temporary: false }, $set: { temporary: false },
$unset: { expiresAt: '' } $unset: { expiresAt: '' },
}, },
callback callback
) )
@ -191,12 +194,9 @@ module.exports = MongoManager = {
{ project_id: 1 }, { project_id: 1 },
{ background: true } { background: true }
) )
},
} }
} ;['getLastCompressedUpdate', 'getProjectMetaData', 'setProjectMetaData'].map(
;[ method =>
'getLastCompressedUpdate',
'getProjectMetaData',
'setProjectMetaData'
].map((method) =>
metrics.timeAsyncMethod(MongoManager, method, 'mongo.MongoManager', logger) metrics.timeAsyncMethod(MongoManager, method, 'mongo.MongoManager', logger)
) )

View file

@ -206,11 +206,11 @@ module.exports = PackManager = {
sz, sz,
meta: { meta: {
start_ts: first.meta.start_ts, start_ts: first.meta.start_ts,
end_ts: last.meta.end_ts end_ts: last.meta.end_ts,
}, },
v: first.v, v: first.v,
v_end: last.v, v_end: last.v,
temporary temporary,
} }
if (temporary) { if (temporary) {
newPack.expiresAt = new Date(Date.now() + 7 * DAYS) newPack.expiresAt = new Date(Date.now() + 7 * DAYS)
@ -252,20 +252,20 @@ module.exports = PackManager = {
_id: lastUpdate._id, _id: lastUpdate._id,
project_id: ObjectId(project_id.toString()), project_id: ObjectId(project_id.toString()),
doc_id: ObjectId(doc_id.toString()), doc_id: ObjectId(doc_id.toString()),
pack: { $exists: true } pack: { $exists: true },
} }
const update = { const update = {
$push: { $push: {
pack: { $each: newUpdates } pack: { $each: newUpdates },
}, },
$inc: { $inc: {
n: n, n: n,
sz: sz sz: sz,
}, },
$set: { $set: {
'meta.end_ts': last.meta.end_ts, 'meta.end_ts': last.meta.end_ts,
v_end: last.v v_end: last.v,
} },
} }
if (lastUpdate.expiresAt && temporary) { if (lastUpdate.expiresAt && temporary) {
update.$set.expiresAt = new Date(Date.now() + 7 * DAYS) update.$set.expiresAt = new Date(Date.now() + 7 * DAYS)
@ -396,7 +396,7 @@ module.exports = PackManager = {
} }
return result1 return result1
})() })()
const loadedPackIds = Array.from(loadedPacks).map((pack) => const loadedPackIds = Array.from(loadedPacks).map(pack =>
pack._id.toString() pack._id.toString()
) )
const packIdsToFetch = _.difference(allPackIds, loadedPackIds) const packIdsToFetch = _.difference(allPackIds, loadedPackIds)
@ -494,7 +494,7 @@ module.exports = PackManager = {
return db.docHistory.updateOne( return db.docHistory.updateOne(
{ _id: pack._id }, { _id: pack._id },
{ $set: { expiresAt: new Date(Date.now() + 7 * DAYS) } }, { $set: { expiresAt: new Date(Date.now() + 7 * DAYS) } },
(err) => callback(err, pack) err => callback(err, pack)
) )
} else { } else {
return callback(null, pack) return callback(null, pack)
@ -552,10 +552,10 @@ module.exports = PackManager = {
}, },
initialiseIndex(project_id, doc_id, callback) { initialiseIndex(project_id, doc_id, callback) {
return PackManager.findCompletedPacks(project_id, doc_id, function ( return PackManager.findCompletedPacks(
err, project_id,
packs doc_id,
) { function (err, packs) {
// console.log 'err', err, 'packs', packs, packs?.length // console.log 'err', err, 'packs', packs, packs?.length
if (err != null) { if (err != null) {
return callback(err) return callback(err)
@ -569,15 +569,16 @@ module.exports = PackManager = {
packs, packs,
callback callback
) )
}) }
)
}, },
updateIndex(project_id, doc_id, callback) { updateIndex(project_id, doc_id, callback) {
// find all packs prior to current pack // find all packs prior to current pack
return PackManager.findUnindexedPacks(project_id, doc_id, function ( return PackManager.findUnindexedPacks(
err, project_id,
newPacks doc_id,
) { function (err, newPacks) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
@ -599,13 +600,14 @@ module.exports = PackManager = {
return callback() return callback()
} }
) )
}) }
)
}, },
findCompletedPacks(project_id, doc_id, callback) { findCompletedPacks(project_id, doc_id, callback) {
const query = { const query = {
doc_id: ObjectId(doc_id.toString()), doc_id: ObjectId(doc_id.toString()),
expiresAt: { $exists: false } expiresAt: { $exists: false },
} }
return db.docHistory return db.docHistory
.find(query, { projection: { pack: false } }) .find(query, { projection: { pack: false } })
@ -631,7 +633,7 @@ module.exports = PackManager = {
findPacks(project_id, doc_id, callback) { findPacks(project_id, doc_id, callback) {
const query = { const query = {
doc_id: ObjectId(doc_id.toString()), doc_id: ObjectId(doc_id.toString()),
expiresAt: { $exists: false } expiresAt: { $exists: false },
} }
return db.docHistory return db.docHistory
.find(query, { projection: { pack: false } }) .find(query, { projection: { pack: false } })
@ -655,10 +657,10 @@ module.exports = PackManager = {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
return PackManager.findCompletedPacks(project_id, doc_id, function ( return PackManager.findCompletedPacks(
err, project_id,
historyPacks doc_id,
) { function (err, historyPacks) {
let pack let pack
if (err != null) { if (err != null) {
return callback(err) return callback(err)
@ -671,7 +673,8 @@ module.exports = PackManager = {
const result = [] const result = []
for (pack of Array.from(historyPacks)) { for (pack of Array.from(historyPacks)) {
if ( if (
(indexResult != null ? indexResult[pack._id] : undefined) == null (indexResult != null ? indexResult[pack._id] : undefined) ==
null
) { ) {
result.push(pack) result.push(pack)
} }
@ -702,14 +705,15 @@ module.exports = PackManager = {
) )
} }
return callback(null, newPacks) return callback(null, newPacks)
}) }
)
}) })
}, },
insertPacksIntoIndexWithLock(project_id, doc_id, newPacks, callback) { insertPacksIntoIndexWithLock(project_id, doc_id, newPacks, callback) {
return LockManager.runWithLock( return LockManager.runWithLock(
keys.historyIndexLock({ doc_id }), keys.historyIndexLock({ doc_id }),
(releaseLock) => releaseLock =>
PackManager._insertPacksIntoIndex( PackManager._insertPacksIntoIndex(
project_id, project_id,
doc_id, doc_id,
@ -726,11 +730,11 @@ module.exports = PackManager = {
{ {
$setOnInsert: { project_id: ObjectId(project_id.toString()) }, $setOnInsert: { project_id: ObjectId(project_id.toString()) },
$push: { $push: {
packs: { $each: newPacks, $sort: { v: 1 } } packs: { $each: newPacks, $sort: { v: 1 } },
} },
}, },
{ {
upsert: true upsert: true,
}, },
callback callback
) )
@ -759,36 +763,36 @@ module.exports = PackManager = {
} }
return async.series( return async.series(
[ [
(cb) => cb =>
PackManager.checkArchiveNotInProgress( PackManager.checkArchiveNotInProgress(
project_id, project_id,
doc_id, doc_id,
pack_id, pack_id,
cb cb
), ),
(cb) => cb =>
PackManager.markPackAsArchiveInProgress( PackManager.markPackAsArchiveInProgress(
project_id, project_id,
doc_id, doc_id,
pack_id, pack_id,
cb cb
), ),
(cb) => cb =>
MongoAWS.archivePack(project_id, doc_id, pack_id, (err) => MongoAWS.archivePack(project_id, doc_id, pack_id, err =>
clearFlagOnError(err, cb) clearFlagOnError(err, cb)
), ),
(cb) => cb =>
PackManager.checkArchivedPack(project_id, doc_id, pack_id, (err) => PackManager.checkArchivedPack(project_id, doc_id, pack_id, err =>
clearFlagOnError(err, cb) clearFlagOnError(err, cb)
), ),
(cb) => PackManager.markPackAsArchived(project_id, doc_id, pack_id, cb), cb => PackManager.markPackAsArchived(project_id, doc_id, pack_id, cb),
(cb) => cb =>
PackManager.setTTLOnArchivedPack( PackManager.setTTLOnArchivedPack(
project_id, project_id,
doc_id, doc_id,
pack_id, pack_id,
callback callback
) ),
], ],
callback callback
) )
@ -802,10 +806,11 @@ module.exports = PackManager = {
if (pack == null) { if (pack == null) {
return callback(new Error('pack not found')) return callback(new Error('pack not found'))
} }
return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function ( return MongoAWS.readArchivedPack(
err, project_id,
result doc_id,
) { pack_id,
function (err, result) {
delete result.last_checked delete result.last_checked
delete pack.last_checked delete pack.last_checked
// need to compare ids as ObjectIds with .equals() // need to compare ids as ObjectIds with .equals()
@ -827,7 +832,7 @@ module.exports = PackManager = {
{ {
pack, pack,
result, result,
jsondiff: JSON.stringify(pack) === JSON.stringify(result) jsondiff: JSON.stringify(pack) === JSON.stringify(result),
}, },
'difference when comparing packs' 'difference when comparing packs'
) )
@ -835,7 +840,8 @@ module.exports = PackManager = {
new Error('pack retrieved from s3 does not match pack in mongo') new Error('pack retrieved from s3 does not match pack in mongo')
) )
} }
}) }
)
}) })
}, },
// Extra methods to test archive/unarchive for a doc_id // Extra methods to test archive/unarchive for a doc_id
@ -870,15 +876,18 @@ module.exports = PackManager = {
// Processing old packs via worker // Processing old packs via worker
processOldPack(project_id, doc_id, pack_id, callback) { processOldPack(project_id, doc_id, pack_id, callback) {
const markAsChecked = (err) => const markAsChecked = err =>
PackManager.markPackAsChecked(project_id, doc_id, pack_id, function ( PackManager.markPackAsChecked(
err2 project_id,
) { doc_id,
pack_id,
function (err2) {
if (err2 != null) { if (err2 != null) {
return callback(err2) return callback(err2)
} }
return callback(err) return callback(err)
}) }
)
logger.log({ project_id, doc_id }, 'processing old packs') logger.log({ project_id, doc_id }, 'processing old packs')
return db.docHistory.findOne({ _id: pack_id }, function (err, pack) { return db.docHistory.findOne({ _id: pack_id }, function (err, pack) {
if (err != null) { if (err != null) {
@ -899,9 +908,10 @@ module.exports = PackManager = {
if (err != null) { if (err != null) {
return markAsChecked(err) return markAsChecked(err)
} }
return PackManager.updateIndexIfNeeded(project_id, doc_id, function ( return PackManager.updateIndexIfNeeded(
err project_id,
) { doc_id,
function (err) {
if (err != null) { if (err != null) {
return markAsChecked(err) return markAsChecked(err)
} }
@ -917,7 +927,10 @@ module.exports = PackManager = {
? unarchivedPacks.length ? unarchivedPacks.length
: undefined) : undefined)
) { ) {
logger.log({ project_id, doc_id }, 'no packs need archiving') logger.log(
{ project_id, doc_id },
'no packs need archiving'
)
return markAsChecked() return markAsChecked()
} }
return async.eachSeries( return async.eachSeries(
@ -934,7 +947,8 @@ module.exports = PackManager = {
) )
} }
) )
}) }
)
} }
) )
}) })
@ -974,7 +988,7 @@ module.exports = PackManager = {
markPackAsFinalisedWithLock(project_id, doc_id, pack_id, callback) { markPackAsFinalisedWithLock(project_id, doc_id, pack_id, callback) {
return LockManager.runWithLock( return LockManager.runWithLock(
keys.historyLock({ doc_id }), keys.historyLock({ doc_id }),
(releaseLock) => releaseLock =>
PackManager._markPackAsFinalised( PackManager._markPackAsFinalised(
project_id, project_id,
doc_id, doc_id,
@ -1050,10 +1064,10 @@ module.exports = PackManager = {
{ project_id, doc_id, pack_id }, { project_id, doc_id, pack_id },
'checking if archive in progress' 'checking if archive in progress'
) )
return PackManager.getPackFromIndex(doc_id, pack_id, function ( return PackManager.getPackFromIndex(
err, doc_id,
result pack_id,
) { function (err, result) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
@ -1067,7 +1081,8 @@ module.exports = PackManager = {
} else { } else {
return callback() return callback()
} }
}) }
)
}, },
markPackAsArchiveInProgress(project_id, doc_id, pack_id, callback) { markPackAsArchiveInProgress(project_id, doc_id, pack_id, callback) {
@ -1078,7 +1093,7 @@ module.exports = PackManager = {
return db.docHistoryIndex.findOneAndUpdate( return db.docHistoryIndex.findOneAndUpdate(
{ {
_id: ObjectId(doc_id.toString()), _id: ObjectId(doc_id.toString()),
packs: { $elemMatch: { _id: pack_id, inS3: { $exists: false } } } packs: { $elemMatch: { _id: pack_id, inS3: { $exists: false } } },
}, },
{ $set: { 'packs.$.inS3': false } }, { $set: { 'packs.$.inS3': false } },
{ projection: { 'packs.$': 1 } }, { projection: { 'packs.$': 1 } },
@ -1106,7 +1121,7 @@ module.exports = PackManager = {
return db.docHistoryIndex.updateOne( return db.docHistoryIndex.updateOne(
{ {
_id: ObjectId(doc_id.toString()), _id: ObjectId(doc_id.toString()),
packs: { $elemMatch: { _id: pack_id, inS3: false } } packs: { $elemMatch: { _id: pack_id, inS3: false } },
}, },
{ $unset: { 'packs.$.inS3': true } }, { $unset: { 'packs.$.inS3': true } },
callback callback
@ -1118,7 +1133,7 @@ module.exports = PackManager = {
return db.docHistoryIndex.findOneAndUpdate( return db.docHistoryIndex.findOneAndUpdate(
{ {
_id: ObjectId(doc_id.toString()), _id: ObjectId(doc_id.toString()),
packs: { $elemMatch: { _id: pack_id, inS3: false } } packs: { $elemMatch: { _id: pack_id, inS3: false } },
}, },
{ $set: { 'packs.$.inS3': true } }, { $set: { 'packs.$.inS3': true } },
{ projection: { 'packs.$': 1 } }, { projection: { 'packs.$': 1 } },
@ -1147,7 +1162,7 @@ module.exports = PackManager = {
return callback() return callback()
} }
) )
} },
} }
// _getOneDayInFutureWithRandomDelay: -> // _getOneDayInFutureWithRandomDelay: ->

View file

@ -53,8 +53,8 @@ if (!source.match(/^[0-9]+$/)) {
} }
return result1 return result1
})() })()
pending = _.filter(result, (row) => pending = _.filter(result, row =>
__guard__(row != null ? row.doc_id : undefined, (x) => __guard__(row != null ? row.doc_id : undefined, x =>
x.match(/^[a-f0-9]{24}$/) x.match(/^[a-f0-9]{24}$/)
) )
) )
@ -101,9 +101,9 @@ const finish = function () {
}) })
} }
process.on('exit', (code) => logger.log({ code }, 'pack archive worker exited')) process.on('exit', code => logger.log({ code }, 'pack archive worker exited'))
const processUpdates = (pending) => const processUpdates = pending =>
async.eachSeries( async.eachSeries(
pending, pending,
function (result, callback) { function (result, callback) {
@ -170,7 +170,7 @@ waitForDb()
processFromOneWeekAgo() processFromOneWeekAgo()
} }
}) })
.catch((err) => { .catch(err => {
logger.fatal({ err }, 'cannot connect to mongo, exiting') logger.fatal({ err }, 'cannot connect to mongo, exiting')
process.exit(1) process.exit(1)
}) })
@ -184,12 +184,12 @@ function processFromOneWeekAgo() {
project_id: { $exists: true }, project_id: { $exists: true },
v_end: { $exists: true }, v_end: { $exists: true },
_id: { $lt: ObjectIdFromDate(oneWeekAgo) }, _id: { $lt: ObjectIdFromDate(oneWeekAgo) },
last_checked: { $lt: oneWeekAgo } last_checked: { $lt: oneWeekAgo },
}, },
{ projection: { _id: 1, doc_id: 1, project_id: 1 } } { projection: { _id: 1, doc_id: 1, project_id: 1 } }
) )
.sort({ .sort({
last_checked: 1 last_checked: 1,
}) })
.limit(LIMIT) .limit(LIMIT)
.toArray(function (err, results) { .toArray(function (err, results) {
@ -198,7 +198,7 @@ function processFromOneWeekAgo() {
finish() finish()
return return
} }
pending = _.uniq(results, false, (result) => result.doc_id.toString()) pending = _.uniq(results, false, result => result.doc_id.toString())
TOTAL = pending.length TOTAL = pending.length
logger.log(`found ${TOTAL} documents to archive`) logger.log(`found ${TOTAL} documents to archive`)
return processUpdates(pending) return processUpdates(pending)

View file

@ -14,7 +14,10 @@
let ProjectIterator let ProjectIterator
const Heap = require('heap') const Heap = require('heap')
module.exports = ProjectIterator = ProjectIterator = class ProjectIterator { module.exports =
ProjectIterator =
ProjectIterator =
class ProjectIterator {
constructor(packs, before, getPackByIdFn) { constructor(packs, before, getPackByIdFn) {
this.before = before this.before = before
this.getPackByIdFn = getPackByIdFn this.getPackByIdFn = getPackByIdFn
@ -48,7 +51,8 @@ module.exports = ProjectIterator = ProjectIterator = class ProjectIterator {
// discard pack that is outside range // discard pack that is outside range
iterator.packs.shift() iterator.packs.shift()
nextPack = iterator.packs[0] nextPack = iterator.packs[0]
lowWaterMark = (nextPack != null ? nextPack.meta.end_ts : undefined) || 0 lowWaterMark =
(nextPack != null ? nextPack.meta.end_ts : undefined) || 0
} }
if ( if (

View file

@ -34,7 +34,7 @@ module.exports = RedisManager = {
callback = function (error, rawUpdates) {} callback = function (error, rawUpdates) {}
} }
try { try {
rawUpdates = Array.from(jsonUpdates || []).map((update) => rawUpdates = Array.from(jsonUpdates || []).map(update =>
JSON.parse(update) JSON.parse(update)
) )
} catch (e) { } catch (e) {
@ -93,11 +93,14 @@ module.exports = RedisManager = {
let cursor = 0 // redis iterator let cursor = 0 // redis iterator
const keySet = {} // use hash to avoid duplicate results const keySet = {} // use hash to avoid duplicate results
// scan over all keys looking for pattern // scan over all keys looking for pattern
var doIteration = (cb) => var doIteration = cb =>
node.scan(cursor, 'MATCH', pattern, 'COUNT', 1000, function ( node.scan(
error, cursor,
reply 'MATCH',
) { pattern,
'COUNT',
1000,
function (error, reply) {
let keys let keys
if (error != null) { if (error != null) {
return callback(error) return callback(error)
@ -112,7 +115,8 @@ module.exports = RedisManager = {
} else { } else {
return doIteration() return doIteration()
} }
}) }
)
return doIteration() return doIteration()
}, },
@ -162,5 +166,5 @@ module.exports = RedisManager = {
return callback(error, doc_ids) return callback(error, doc_ids)
} }
) )
} },
} }

View file

@ -44,5 +44,5 @@ module.exports = RestoreManager = {
) )
} }
) )
} },
} }

View file

@ -42,16 +42,16 @@ module.exports = UpdateCompressor = {
const splitUpdates = [] const splitUpdates = []
for (const update of Array.from(updates)) { for (const update of Array.from(updates)) {
// Reject any non-insert or delete ops, i.e. comments // Reject any non-insert or delete ops, i.e. comments
const ops = update.op.filter((o) => o.i != null || o.d != null) const ops = update.op.filter(o => o.i != null || o.d != null)
if (ops.length === 0) { if (ops.length === 0) {
splitUpdates.push({ splitUpdates.push({
op: UpdateCompressor.NOOP, op: UpdateCompressor.NOOP,
meta: { meta: {
start_ts: update.meta.start_ts || update.meta.ts, start_ts: update.meta.start_ts || update.meta.ts,
end_ts: update.meta.end_ts || update.meta.ts, end_ts: update.meta.end_ts || update.meta.ts,
user_id: update.meta.user_id user_id: update.meta.user_id,
}, },
v: update.v v: update.v,
}) })
} else { } else {
for (const op of Array.from(ops)) { for (const op of Array.from(ops)) {
@ -60,9 +60,9 @@ module.exports = UpdateCompressor = {
meta: { meta: {
start_ts: update.meta.start_ts || update.meta.ts, start_ts: update.meta.start_ts || update.meta.ts,
end_ts: update.meta.end_ts || update.meta.ts, end_ts: update.meta.end_ts || update.meta.ts,
user_id: update.meta.user_id user_id: update.meta.user_id,
}, },
v: update.v v: update.v,
}) })
} }
} }
@ -82,7 +82,7 @@ module.exports = UpdateCompressor = {
const nextUpdate = { const nextUpdate = {
op: [], op: [],
meta: update.meta, meta: update.meta,
v: update.v v: update.v,
} }
if (update.op !== UpdateCompressor.NOOP) { if (update.op !== UpdateCompressor.NOOP) {
nextUpdate.op.push(update.op) nextUpdate.op.push(update.op)
@ -97,7 +97,7 @@ module.exports = UpdateCompressor = {
if ( if (
__guard__( __guard__(
lastPreviousUpdate != null ? lastPreviousUpdate.op : undefined, lastPreviousUpdate != null ? lastPreviousUpdate.op : undefined,
(x) => x.length x => x.length
) > 1 ) > 1
) { ) {
// if the last previous update was an array op, don't compress onto it. // if the last previous update was an array op, don't compress onto it.
@ -144,18 +144,18 @@ module.exports = UpdateCompressor = {
meta: { meta: {
user_id: firstUpdate.meta.user_id || null, user_id: firstUpdate.meta.user_id || null,
start_ts: firstUpdate.meta.start_ts || firstUpdate.meta.ts, start_ts: firstUpdate.meta.start_ts || firstUpdate.meta.ts,
end_ts: firstUpdate.meta.end_ts || firstUpdate.meta.ts end_ts: firstUpdate.meta.end_ts || firstUpdate.meta.ts,
}, },
v: firstUpdate.v v: firstUpdate.v,
} }
secondUpdate = { secondUpdate = {
op: secondUpdate.op, op: secondUpdate.op,
meta: { meta: {
user_id: secondUpdate.meta.user_id || null, user_id: secondUpdate.meta.user_id || null,
start_ts: secondUpdate.meta.start_ts || secondUpdate.meta.ts, start_ts: secondUpdate.meta.start_ts || secondUpdate.meta.ts,
end_ts: secondUpdate.meta.end_ts || secondUpdate.meta.ts end_ts: secondUpdate.meta.end_ts || secondUpdate.meta.ts,
}, },
v: secondUpdate.v v: secondUpdate.v,
} }
if (firstUpdate.meta.user_id !== secondUpdate.meta.user_id) { if (firstUpdate.meta.user_id !== secondUpdate.meta.user_id) {
@ -192,14 +192,14 @@ module.exports = UpdateCompressor = {
meta: { meta: {
start_ts: firstUpdate.meta.start_ts, start_ts: firstUpdate.meta.start_ts,
end_ts: secondUpdate.meta.end_ts, end_ts: secondUpdate.meta.end_ts,
user_id: firstUpdate.meta.user_id user_id: firstUpdate.meta.user_id,
}, },
op: { op: {
p: firstOp.p, p: firstOp.p,
i: strInject(firstOp.i, secondOp.p - firstOp.p, secondOp.i) i: strInject(firstOp.i, secondOp.p - firstOp.p, secondOp.i),
},
v: secondUpdate.v,
}, },
v: secondUpdate.v
}
] ]
// Two deletes // Two deletes
} else if ( } else if (
@ -214,14 +214,14 @@ module.exports = UpdateCompressor = {
meta: { meta: {
start_ts: firstUpdate.meta.start_ts, start_ts: firstUpdate.meta.start_ts,
end_ts: secondUpdate.meta.end_ts, end_ts: secondUpdate.meta.end_ts,
user_id: firstUpdate.meta.user_id user_id: firstUpdate.meta.user_id,
}, },
op: { op: {
p: secondOp.p, p: secondOp.p,
d: strInject(secondOp.d, firstOp.p - secondOp.p, firstOp.d) d: strInject(secondOp.d, firstOp.p - secondOp.p, firstOp.d),
},
v: secondUpdate.v,
}, },
v: secondUpdate.v
}
] ]
// An insert and then a delete // An insert and then a delete
} else if ( } else if (
@ -240,14 +240,14 @@ module.exports = UpdateCompressor = {
meta: { meta: {
start_ts: firstUpdate.meta.start_ts, start_ts: firstUpdate.meta.start_ts,
end_ts: secondUpdate.meta.end_ts, end_ts: secondUpdate.meta.end_ts,
user_id: firstUpdate.meta.user_id user_id: firstUpdate.meta.user_id,
}, },
op: { op: {
p: firstOp.p, p: firstOp.p,
i: insert i: insert,
},
v: secondUpdate.v,
}, },
v: secondUpdate.v
}
] ]
} else { } else {
// This will only happen if the delete extends outside the insert // This will only happen if the delete extends outside the insert
@ -269,14 +269,14 @@ module.exports = UpdateCompressor = {
meta: { meta: {
start_ts: firstUpdate.meta.start_ts, start_ts: firstUpdate.meta.start_ts,
end_ts: secondUpdate.meta.end_ts, end_ts: secondUpdate.meta.end_ts,
user_id: firstUpdate.meta.user_id user_id: firstUpdate.meta.user_id,
}, },
op: { op: {
p: firstOp.p, p: firstOp.p,
i: '' i: '',
},
v: secondUpdate.v,
}, },
v: secondUpdate.v
}
] ]
} else { } else {
return diff_ops.map(function (op) { return diff_ops.map(function (op) {
@ -285,10 +285,10 @@ module.exports = UpdateCompressor = {
meta: { meta: {
start_ts: firstUpdate.meta.start_ts, start_ts: firstUpdate.meta.start_ts,
end_ts: secondUpdate.meta.end_ts, end_ts: secondUpdate.meta.end_ts,
user_id: firstUpdate.meta.user_id user_id: firstUpdate.meta.user_id,
}, },
op, op,
v: secondUpdate.v v: secondUpdate.v,
} }
}) })
} }
@ -315,13 +315,13 @@ module.exports = UpdateCompressor = {
if (type === this.ADDED) { if (type === this.ADDED) {
ops.push({ ops.push({
i: content, i: content,
p: position p: position,
}) })
position += content.length position += content.length
} else if (type === this.REMOVED) { } else if (type === this.REMOVED) {
ops.push({ ops.push({
d: content, d: content,
p: position p: position,
}) })
} else if (type === this.UNCHANGED) { } else if (type === this.UNCHANGED) {
position += content.length position += content.length
@ -330,7 +330,7 @@ module.exports = UpdateCompressor = {
} }
} }
return ops return ops
} },
} }
function __guard__(value, transform) { function __guard__(value, transform) {

View file

@ -22,20 +22,18 @@ module.exports = UpdateTrimmer = {
if (callback == null) { if (callback == null) {
callback = function (error, shouldTrim) {} callback = function (error, shouldTrim) {}
} }
return MongoManager.getProjectMetaData(project_id, function ( return MongoManager.getProjectMetaData(
error, project_id,
metadata function (error, metadata) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
if (metadata != null ? metadata.preserveHistory : undefined) { if (metadata != null ? metadata.preserveHistory : undefined) {
return callback(null, false) return callback(null, false)
} else { } else {
return WebApiManager.getProjectDetails(project_id, function ( return WebApiManager.getProjectDetails(
error, project_id,
details function (error, details) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -43,7 +41,7 @@ module.exports = UpdateTrimmer = {
if ( if (
__guard__( __guard__(
details != null ? details.features : undefined, details != null ? details.features : undefined,
(x) => x.versioning x => x.versioning
) )
) { ) {
return MongoManager.setProjectMetaData( return MongoManager.setProjectMetaData(
@ -53,24 +51,27 @@ module.exports = UpdateTrimmer = {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return MongoManager.upgradeHistory(project_id, function ( return MongoManager.upgradeHistory(
error project_id,
) { function (error) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return callback(null, false) return callback(null, false)
}) }
)
} }
) )
} else { } else {
return callback(null, true) return callback(null, true)
} }
})
} }
}) )
} }
} }
)
},
}
function __guard__(value, transform) { function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null return typeof value !== 'undefined' && value !== null

View file

@ -50,7 +50,7 @@ module.exports = UpdatesManager = {
const op = rawUpdates[i] const op = rawUpdates[i]
if (i > 0) { if (i > 0) {
const thisVersion = op != null ? op.v : undefined const thisVersion = op != null ? op.v : undefined
const prevVersion = __guard__(rawUpdates[i - 1], (x) => x.v) const prevVersion = __guard__(rawUpdates[i - 1], x => x.v)
if (!(prevVersion < thisVersion)) { if (!(prevVersion < thisVersion)) {
logger.error( logger.error(
{ {
@ -59,7 +59,7 @@ module.exports = UpdatesManager = {
rawUpdates, rawUpdates,
temporary, temporary,
thisVersion, thisVersion,
prevVersion prevVersion,
}, },
'op versions out of order' 'op versions out of order'
) )
@ -69,11 +69,9 @@ module.exports = UpdatesManager = {
// FIXME: we no longer need the lastCompressedUpdate, so change functions not to need it // FIXME: we no longer need the lastCompressedUpdate, so change functions not to need it
// CORRECTION: we do use it to log the time in case of error // CORRECTION: we do use it to log the time in case of error
return MongoManager.peekLastCompressedUpdate(doc_id, function ( return MongoManager.peekLastCompressedUpdate(
error, doc_id,
lastCompressedUpdate, function (error, lastCompressedUpdate, lastVersion) {
lastVersion
) {
// lastCompressedUpdate is the most recent update in Mongo, and // lastCompressedUpdate is the most recent update in Mongo, and
// lastVersion is its sharejs version number. // lastVersion is its sharejs version number.
// //
@ -105,7 +103,7 @@ module.exports = UpdatesManager = {
lastCompressedUpdate != null lastCompressedUpdate != null
? lastCompressedUpdate.meta ? lastCompressedUpdate.meta
: undefined, : undefined,
(x1) => x1.end_ts x1 => x1.end_ts
) )
const last_timestamp = ts != null ? new Date(ts) : 'unknown time' const last_timestamp = ts != null ? new Date(ts) : 'unknown time'
error = new Error( error = new Error(
@ -118,7 +116,7 @@ module.exports = UpdatesManager = {
project_id, project_id,
prev_end_ts: ts, prev_end_ts: ts,
temporary, temporary,
lastCompressedUpdate lastCompressedUpdate,
}, },
'inconsistent doc versions' 'inconsistent doc versions'
) )
@ -192,7 +190,7 @@ module.exports = UpdatesManager = {
lastCompressedUpdate != null lastCompressedUpdate != null
? lastCompressedUpdate.v ? lastCompressedUpdate.v
: undefined, : undefined,
new_v: result.v new_v: result.v,
}, },
'inserted updates into pack' 'inserted updates into pack'
) )
@ -200,7 +198,8 @@ module.exports = UpdatesManager = {
return callback() return callback()
} }
) )
}) }
)
}, },
// Check whether the updates are temporary (per-project property) // Check whether the updates are temporary (per-project property)
@ -208,15 +207,15 @@ module.exports = UpdatesManager = {
if (callback == null) { if (callback == null) {
callback = function (error, temporary) {} callback = function (error, temporary) {}
} }
return UpdateTrimmer.shouldTrimUpdates(project_id, function ( return UpdateTrimmer.shouldTrimUpdates(
error, project_id,
temporary function (error, temporary) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return callback(null, temporary) return callback(null, temporary)
}) }
)
}, },
// Check for project id on document history (per-document property) // Check for project id on document history (per-document property)
@ -248,10 +247,9 @@ module.exports = UpdatesManager = {
} }
const { length } = docUpdates const { length } = docUpdates
// parse the redis strings into ShareJs updates // parse the redis strings into ShareJs updates
return RedisManager.expandDocUpdates(docUpdates, function ( return RedisManager.expandDocUpdates(
error, docUpdates,
rawUpdates function (error, rawUpdates) {
) {
if (error != null) { if (error != null) {
logger.err( logger.err(
{ project_id, doc_id, docUpdates }, { project_id, doc_id, docUpdates },
@ -312,7 +310,8 @@ module.exports = UpdatesManager = {
) )
} }
) )
}) }
)
} }
) )
}, },
@ -322,10 +321,9 @@ module.exports = UpdatesManager = {
if (callback == null) { if (callback == null) {
callback = function (error) {} callback = function (error) {}
} }
return UpdatesManager._prepareProjectForUpdates(project_id, function ( return UpdatesManager._prepareProjectForUpdates(
error, project_id,
temporary function (error, temporary) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -335,7 +333,8 @@ module.exports = UpdatesManager = {
temporary, temporary,
callback callback
) )
}) }
)
}, },
// Process updates for a doc when the whole project is flushed (internal method) // Process updates for a doc when the whole project is flushed (internal method)
@ -348,15 +347,16 @@ module.exports = UpdatesManager = {
if (callback == null) { if (callback == null) {
callback = function (error) {} callback = function (error) {}
} }
return UpdatesManager._prepareDocForUpdates(project_id, doc_id, function ( return UpdatesManager._prepareDocForUpdates(
error project_id,
) { doc_id,
function (error) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return LockManager.runWithLock( return LockManager.runWithLock(
keys.historyLock({ doc_id }), keys.historyLock({ doc_id }),
(releaseLock) => releaseLock =>
UpdatesManager.processUncompressedUpdates( UpdatesManager.processUncompressedUpdates(
project_id, project_id,
doc_id, doc_id,
@ -365,7 +365,8 @@ module.exports = UpdatesManager = {
), ),
callback callback
) )
}) }
)
}, },
// Process all updates for a project, only check project-level information once // Process all updates for a project, only check project-level information once
@ -373,21 +374,19 @@ module.exports = UpdatesManager = {
if (callback == null) { if (callback == null) {
callback = function (error) {} callback = function (error) {}
} }
return RedisManager.getDocIdsWithHistoryOps(project_id, function ( return RedisManager.getDocIdsWithHistoryOps(
error, project_id,
doc_ids function (error, doc_ids) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return UpdatesManager._prepareProjectForUpdates(project_id, function ( return UpdatesManager._prepareProjectForUpdates(
error, project_id,
temporary function (error, temporary) {
) {
const jobs = [] const jobs = []
for (const doc_id of Array.from(doc_ids)) { for (const doc_id of Array.from(doc_ids)) {
;((doc_id) => ;(doc_id =>
jobs.push((cb) => jobs.push(cb =>
UpdatesManager._processUncompressedUpdatesForDocWithLock( UpdatesManager._processUncompressedUpdatesForDocWithLock(
project_id, project_id,
doc_id, doc_id,
@ -397,8 +396,10 @@ module.exports = UpdatesManager = {
))(doc_id) ))(doc_id)
} }
return async.parallelLimit(jobs, 5, callback) return async.parallelLimit(jobs, 5, callback)
}) }
}) )
}
)
}, },
// flush all outstanding changes // flush all outstanding changes
@ -417,7 +418,7 @@ module.exports = UpdatesManager = {
logger.log( logger.log(
{ {
count: project_ids != null ? project_ids.length : undefined, count: project_ids != null ? project_ids.length : undefined,
project_ids project_ids,
}, },
'found projects' 'found projects'
) )
@ -426,11 +427,11 @@ module.exports = UpdatesManager = {
const selectedProjects = const selectedProjects =
limit < 0 ? project_ids : project_ids.slice(0, limit) limit < 0 ? project_ids : project_ids.slice(0, limit)
for (project_id of Array.from(selectedProjects)) { for (project_id of Array.from(selectedProjects)) {
;((project_id) => ;(project_id =>
jobs.push((cb) => jobs.push(cb =>
UpdatesManager.processUncompressedUpdatesForProject( UpdatesManager.processUncompressedUpdatesForProject(
project_id, project_id,
(err) => cb(null, { failed: err != null, project_id }) err => cb(null, { failed: err != null, project_id })
) )
))(project_id) ))(project_id)
} }
@ -460,7 +461,7 @@ module.exports = UpdatesManager = {
return callback(null, { return callback(null, {
failed: failedProjects, failed: failedProjects,
succeeded: succeededProjects, succeeded: succeededProjects,
all: project_ids all: project_ids,
}) })
}) })
}) })
@ -485,7 +486,7 @@ module.exports = UpdatesManager = {
return callback(error) return callback(error)
} }
// function to get doc_ids for each project // function to get doc_ids for each project
const task = (cb) => const task = cb =>
async.concatSeries( async.concatSeries(
all_project_ids, all_project_ids,
RedisManager.getDocIdsWithHistoryOps, RedisManager.getDocIdsWithHistoryOps,
@ -542,10 +543,11 @@ module.exports = UpdatesManager = {
if (callback == null) { if (callback == null) {
callback = function (error, updates) {} callback = function (error, updates) {}
} }
return UpdatesManager.getDocUpdates(project_id, doc_id, options, function ( return UpdatesManager.getDocUpdates(
error, project_id,
updates doc_id,
) { options,
function (error, updates) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -555,7 +557,8 @@ module.exports = UpdatesManager = {
} }
return callback(null, updates) return callback(null, updates)
}) })
}) }
)
}, },
getSummarizedProjectUpdates(project_id, options, callback) { getSummarizedProjectUpdates(project_id, options, callback) {
@ -577,10 +580,10 @@ module.exports = UpdatesManager = {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return PackManager.makeProjectIterator(project_id, before, function ( return PackManager.makeProjectIterator(
err, project_id,
iterator before,
) { function (err, iterator) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
@ -588,9 +591,10 @@ module.exports = UpdatesManager = {
return async.whilst( return async.whilst(
() => () =>
// console.log "checking iterator.done", iterator.done() // console.log "checking iterator.done", iterator.done()
summarizedUpdates.length < options.min_count && !iterator.done(), summarizedUpdates.length < options.min_count &&
!iterator.done(),
(cb) => cb =>
iterator.next(function (err, partialUpdates) { iterator.next(function (err, partialUpdates) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
@ -626,14 +630,15 @@ module.exports = UpdatesManager = {
} }
) )
) )
}) }
)
} }
) )
}, },
exportProject(projectId, consumer) { exportProject(projectId, consumer) {
// Flush anything before collecting updates. // Flush anything before collecting updates.
UpdatesManager.processUncompressedUpdatesForProject(projectId, (err) => { UpdatesManager.processUncompressedUpdatesForProject(projectId, err => {
if (err) return consumer(err) if (err) return consumer(err)
// Fetch all the packs. // Fetch all the packs.
@ -646,7 +651,7 @@ module.exports = UpdatesManager = {
async.whilst( async.whilst(
() => !iterator.done(), () => !iterator.done(),
(cb) => cb =>
iterator.next((err, updatesFromASinglePack) => { iterator.next((err, updatesFromASinglePack) => {
if (err) return cb(err) if (err) return cb(err)
@ -656,7 +661,7 @@ module.exports = UpdatesManager = {
// call. // call.
return cb() return cb()
} }
updatesFromASinglePack.forEach((update) => { updatesFromASinglePack.forEach(update => {
accumulatedUserIds.add( accumulatedUserIds.add(
// Super defensive access on update details. // Super defensive access on update details.
String(update && update.meta && update.meta.user_id) String(update && update.meta && update.meta.user_id)
@ -666,7 +671,7 @@ module.exports = UpdatesManager = {
consumer(null, { updates: updatesFromASinglePack }, cb) consumer(null, { updates: updatesFromASinglePack }, cb)
}), }),
(err) => { err => {
if (err) return consumer(err) if (err) return consumer(err)
// Adding undefined can happen for broken updates. // Adding undefined can happen for broken updates.
@ -674,7 +679,7 @@ module.exports = UpdatesManager = {
consumer(null, { consumer(null, {
updates: [], updates: [],
userIds: Array.from(accumulatedUserIds).sort() userIds: Array.from(accumulatedUserIds).sort(),
}) })
} }
) )
@ -689,8 +694,8 @@ module.exports = UpdatesManager = {
const jobs = [] const jobs = []
const fetchedUserInfo = {} const fetchedUserInfo = {}
for (const user_id in users) { for (const user_id in users) {
;((user_id) => ;(user_id =>
jobs.push((callback) => jobs.push(callback =>
WebApiManager.getUserInfo(user_id, function (error, userInfo) { WebApiManager.getUserInfo(user_id, function (error, userInfo) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
@ -722,10 +727,9 @@ module.exports = UpdatesManager = {
} }
} }
return UpdatesManager.fetchUserInfo(users, function ( return UpdatesManager.fetchUserInfo(
error, users,
fetchedUserInfo function (error, fetchedUserInfo) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -737,7 +741,8 @@ module.exports = UpdatesManager = {
} }
} }
return callback(null, updates) return callback(null, updates)
}) }
)
}, },
fillSummarizedUserInfo(updates, callback) { fillSummarizedUserInfo(updates, callback) {
@ -755,10 +760,9 @@ module.exports = UpdatesManager = {
} }
} }
return UpdatesManager.fetchUserInfo(users, function ( return UpdatesManager.fetchUserInfo(
error, users,
fetchedUserInfo function (error, fetchedUserInfo) {
) {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -775,7 +779,8 @@ module.exports = UpdatesManager = {
} }
} }
return callback(null, updates) return callback(null, updates)
}) }
)
}, },
_validUserId(user_id) { _validUserId(user_id) {
@ -830,7 +835,7 @@ module.exports = UpdatesManager = {
// check if the user in this update is already present in the earliest update, // check if the user in this update is already present in the earliest update,
// if not, add them to the users list of the earliest update // if not, add them to the users list of the earliest update
earliestUpdate.meta.user_ids = _.union(earliestUpdate.meta.user_ids, [ earliestUpdate.meta.user_ids = _.union(earliestUpdate.meta.user_ids, [
update.meta.user_id update.meta.user_id,
]) ])
doc_id = update.doc_id.toString() doc_id = update.doc_id.toString()
@ -841,7 +846,7 @@ module.exports = UpdatesManager = {
} else { } else {
earliestUpdate.docs[doc_id] = { earliestUpdate.docs[doc_id] = {
fromV: update.v, fromV: update.v,
toV: update.v toV: update.v,
} }
} }
@ -858,14 +863,14 @@ module.exports = UpdatesManager = {
meta: { meta: {
user_ids: [], user_ids: [],
start_ts: update.meta.start_ts, start_ts: update.meta.start_ts,
end_ts: update.meta.end_ts end_ts: update.meta.end_ts,
}, },
docs: {} docs: {},
} }
newUpdate.docs[update.doc_id.toString()] = { newUpdate.docs[update.doc_id.toString()] = {
fromV: update.v, fromV: update.v,
toV: update.v toV: update.v,
} }
newUpdate.meta.user_ids.push(update.meta.user_id) newUpdate.meta.user_ids.push(update.meta.user_id)
summarizedUpdates.push(newUpdate) summarizedUpdates.push(newUpdate)
@ -873,7 +878,7 @@ module.exports = UpdatesManager = {
} }
return summarizedUpdates return summarizedUpdates
} },
} }
function __guard__(value, transform) { function __guard__(value, transform) {

View file

@ -36,8 +36,8 @@ module.exports = WebApiManager = {
auth: { auth: {
user: Settings.apis.web.user, user: Settings.apis.web.user,
pass: Settings.apis.web.pass, pass: Settings.apis.web.pass,
sendImmediately: true sendImmediately: true,
} },
}, },
function (error, res, body) { function (error, res, body) {
if (error != null) { if (error != null) {
@ -86,7 +86,7 @@ module.exports = WebApiManager = {
id: user.id, id: user.id,
email: user.email, email: user.email,
first_name: user.first_name, first_name: user.first_name,
last_name: user.last_name last_name: user.last_name,
}) })
}) })
}, },
@ -112,5 +112,5 @@ module.exports = WebApiManager = {
} }
return callback(null, project) return callback(null, project)
}) })
} },
} }

View file

@ -38,5 +38,5 @@ module.exports = {
db, db,
ObjectId, ObjectId,
closeDb, closeDb,
waitForDb waitForDb,
} }

View file

@ -178,7 +178,7 @@ diff_match_patch.prototype.diff_compute_ = function (
diffs = [ diffs = [
[DIFF_INSERT, longtext.substring(0, i)], [DIFF_INSERT, longtext.substring(0, i)],
[DIFF_EQUAL, shorttext], [DIFF_EQUAL, shorttext],
[DIFF_INSERT, longtext.substring(i + shorttext.length)] [DIFF_INSERT, longtext.substring(i + shorttext.length)],
] ]
// Swap insertions for deletions if diff is reversed. // Swap insertions for deletions if diff is reversed.
if (text1.length > text2.length) { if (text1.length > text2.length) {
@ -192,7 +192,7 @@ diff_match_patch.prototype.diff_compute_ = function (
// After the previous speedup, the character can't be an equality. // After the previous speedup, the character can't be an equality.
return [ return [
[DIFF_DELETE, text1], [DIFF_DELETE, text1],
[DIFF_INSERT, text2] [DIFF_INSERT, text2],
] ]
} }
@ -415,7 +415,7 @@ diff_match_patch.prototype.diff_bisect_ = function (text1, text2, deadline) {
// number of diffs equals number of characters, no commonality at all. // number of diffs equals number of characters, no commonality at all.
return [ return [
[DIFF_DELETE, text1], [DIFF_DELETE, text1],
[DIFF_INSERT, text2] [DIFF_INSERT, text2],
] ]
} }
@ -716,7 +716,7 @@ diff_match_patch.prototype.diff_halfMatch_ = function (text1, text2) {
best_longtext_b, best_longtext_b,
best_shorttext_a, best_shorttext_a,
best_shorttext_b, best_shorttext_b,
best_common best_common,
] ]
} else { } else {
return null return null
@ -809,7 +809,7 @@ diff_match_patch.prototype.diff_cleanupSemantic = function (diffs) {
// Duplicate record. // Duplicate record.
diffs.splice(equalities[equalitiesLength - 1], 0, [ diffs.splice(equalities[equalitiesLength - 1], 0, [
DIFF_DELETE, DIFF_DELETE,
lastequality lastequality,
]) ])
// Change second copy to insert. // Change second copy to insert.
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT
@ -859,7 +859,7 @@ diff_match_patch.prototype.diff_cleanupSemantic = function (diffs) {
// Overlap found. Insert an equality and trim the surrounding edits. // Overlap found. Insert an equality and trim the surrounding edits.
diffs.splice(pointer, 0, [ diffs.splice(pointer, 0, [
DIFF_EQUAL, DIFF_EQUAL,
insertion.substring(0, overlap_length1) insertion.substring(0, overlap_length1),
]) ])
diffs[pointer - 1][1] = deletion.substring( diffs[pointer - 1][1] = deletion.substring(
0, 0,
@ -877,7 +877,7 @@ diff_match_patch.prototype.diff_cleanupSemantic = function (diffs) {
// Insert an equality and swap and trim the surrounding edits. // Insert an equality and swap and trim the surrounding edits.
diffs.splice(pointer, 0, [ diffs.splice(pointer, 0, [
DIFF_EQUAL, DIFF_EQUAL,
deletion.substring(0, overlap_length2) deletion.substring(0, overlap_length2),
]) ])
diffs[pointer - 1][0] = DIFF_INSERT diffs[pointer - 1][0] = DIFF_INSERT
diffs[pointer - 1][1] = insertion.substring( diffs[pointer - 1][1] = insertion.substring(
@ -1093,7 +1093,7 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function (diffs) {
// Duplicate record. // Duplicate record.
diffs.splice(equalities[equalitiesLength - 1], 0, [ diffs.splice(equalities[equalitiesLength - 1], 0, [
DIFF_DELETE, DIFF_DELETE,
lastequality lastequality,
]) ])
// Change second copy to insert. // Change second copy to insert.
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT
@ -1156,13 +1156,12 @@ diff_match_patch.prototype.diff_cleanupMerge = function (diffs) {
diffs[pointer - count_delete - count_insert - 1][0] == diffs[pointer - count_delete - count_insert - 1][0] ==
DIFF_EQUAL DIFF_EQUAL
) { ) {
diffs[ diffs[pointer - count_delete - count_insert - 1][1] +=
pointer - count_delete - count_insert - 1 text_insert.substring(0, commonlength)
][1] += text_insert.substring(0, commonlength)
} else { } else {
diffs.splice(0, 0, [ diffs.splice(0, 0, [
DIFF_EQUAL, DIFF_EQUAL,
text_insert.substring(0, commonlength) text_insert.substring(0, commonlength),
]) ])
pointer++ pointer++
} }
@ -1189,12 +1188,12 @@ diff_match_patch.prototype.diff_cleanupMerge = function (diffs) {
if (count_delete === 0) { if (count_delete === 0) {
diffs.splice(pointer - count_insert, count_delete + count_insert, [ diffs.splice(pointer - count_insert, count_delete + count_insert, [
DIFF_INSERT, DIFF_INSERT,
text_insert text_insert,
]) ])
} else if (count_insert === 0) { } else if (count_insert === 0) {
diffs.splice(pointer - count_delete, count_delete + count_insert, [ diffs.splice(pointer - count_delete, count_delete + count_insert, [
DIFF_DELETE, DIFF_DELETE,
text_delete text_delete,
]) ])
} else { } else {
diffs.splice( diffs.splice(

View file

@ -6,18 +6,18 @@ module.exports = {
mongo: { mongo: {
options: { options: {
useUnifiedTopology: useUnifiedTopology:
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true' (process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true',
}, },
url: url:
process.env.MONGO_CONNECTION_STRING || process.env.MONGO_CONNECTION_STRING ||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex` `mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
}, },
internal: { internal: {
trackchanges: { trackchanges: {
port: 3015, port: 3015,
host: process.env.LISTEN_ADDRESS || 'localhost' host: process.env.LISTEN_ADDRESS || 'localhost',
} },
}, },
apis: { apis: {
documentupdater: { documentupdater: {
@ -25,18 +25,18 @@ module.exports = {
process.env.DOCUMENT_UPDATER_HOST || process.env.DOCUMENT_UPDATER_HOST ||
process.env.DOCUPDATER_HOST || process.env.DOCUPDATER_HOST ||
'localhost' 'localhost'
}:3003` }:3003`,
}, },
docstore: { docstore: {
url: `http://${process.env.DOCSTORE_HOST || 'localhost'}:3016` url: `http://${process.env.DOCSTORE_HOST || 'localhost'}:3016`,
}, },
web: { web: {
url: `http://${ url: `http://${
process.env.WEB_API_HOST || process.env.WEB_HOST || 'localhost' process.env.WEB_API_HOST || process.env.WEB_HOST || 'localhost'
}:${process.env.WEB_API_PORT || process.env.WEB_PORT || 3000}`, }:${process.env.WEB_API_PORT || process.env.WEB_PORT || 3000}`,
user: process.env.WEB_API_USER || 'sharelatex', user: process.env.WEB_API_USER || 'sharelatex',
pass: process.env.WEB_API_PASSWORD || 'password' pass: process.env.WEB_API_PASSWORD || 'password',
} },
}, },
redis: { redis: {
lock: { lock: {
@ -49,8 +49,8 @@ module.exports = {
}, },
historyIndexLock({ project_id: projectId }) { historyIndexLock({ project_id: projectId }) {
return `HistoryIndexLock:{${projectId}}` return `HistoryIndexLock:{${projectId}}`
} },
} },
}, },
history: { history: {
host: process.env.REDIS_HOST || 'localhost', host: process.env.REDIS_HOST || 'localhost',
@ -62,9 +62,9 @@ module.exports = {
}, },
docsWithHistoryOps({ project_id: projectId }) { docsWithHistoryOps({ project_id: projectId }) {
return `DocsWithHistoryOps:{${projectId}}` return `DocsWithHistoryOps:{${projectId}}`
} },
} },
} },
}, },
trackchanges: { trackchanges: {
@ -72,19 +72,19 @@ module.exports = {
key: process.env.AWS_ACCESS_KEY_ID, key: process.env.AWS_ACCESS_KEY_ID,
secret: process.env.AWS_SECRET_ACCESS_KEY, secret: process.env.AWS_SECRET_ACCESS_KEY,
endpoint: process.env.AWS_S3_ENDPOINT, endpoint: process.env.AWS_S3_ENDPOINT,
pathStyle: process.env.AWS_S3_PATH_STYLE === 'true' pathStyle: process.env.AWS_S3_PATH_STYLE === 'true',
}, },
stores: { stores: {
doc_history: process.env.AWS_BUCKET doc_history: process.env.AWS_BUCKET,
}, },
continueOnError: process.env.TRACK_CHANGES_CONTINUE_ON_ERROR || false continueOnError: process.env.TRACK_CHANGES_CONTINUE_ON_ERROR || false,
}, },
path: { path: {
dumpFolder: Path.join(TMP_DIR, 'dumpFolder') dumpFolder: Path.join(TMP_DIR, 'dumpFolder'),
}, },
sentry: { sentry: {
dsn: process.env.SENTRY_DSN dsn: process.env.SENTRY_DSN,
} },
} }

View file

@ -39,20 +39,20 @@ describe('Appending doc ops to the history', function () {
{ {
op: [{ i: 'f', p: 3 }], op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
}, },
{ {
op: [{ i: 'o', p: 4 }], op: [{ i: 'o', p: 4 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 4 v: 4,
}, },
{ {
op: [{ i: 'o', p: 5 }], op: [{ i: 'o', p: 5 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 5 v: 5,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -76,8 +76,8 @@ describe('Appending doc ops to the history', function () {
return expect(this.updates[0].pack[0].op).to.deep.equal([ return expect(this.updates[0].pack[0].op).to.deep.equal([
{ {
p: 3, p: 3,
i: 'foo' i: 'foo',
} },
]) ])
}) })
@ -121,20 +121,20 @@ describe('Appending doc ops to the history', function () {
{ {
op: [{ i: 'f', p: 3 }], op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
}, },
{ {
op: [{ i: 'o', p: 4 }], op: [{ i: 'o', p: 4 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 4 v: 4,
}, },
{ {
op: [{ i: 'o', p: 5 }], op: [{ i: 'o', p: 5 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 5 v: 5,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -162,20 +162,20 @@ describe('Appending doc ops to the history', function () {
{ {
op: [{ i: 'b', p: 6 }], op: [{ i: 'b', p: 6 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 6 v: 6,
}, },
{ {
op: [{ i: 'a', p: 7 }], op: [{ i: 'a', p: 7 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 7 v: 7,
}, },
{ {
op: [{ i: 'r', p: 8 }], op: [{ i: 'r', p: 8 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 8 v: 8,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -199,8 +199,8 @@ describe('Appending doc ops to the history', function () {
return expect(this.updates[0].pack[1].op).to.deep.equal([ return expect(this.updates[0].pack[1].op).to.deep.equal([
{ {
p: 6, p: 6,
i: 'bar' i: 'bar',
} },
]) ])
}) })
@ -219,20 +219,20 @@ describe('Appending doc ops to the history', function () {
{ {
op: [{ i: 'b', p: 6 }], op: [{ i: 'b', p: 6 }],
meta: { ts: Date.now() + oneDay, user_id: this.user_id }, meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 6 v: 6,
}, },
{ {
op: [{ i: 'a', p: 7 }], op: [{ i: 'a', p: 7 }],
meta: { ts: Date.now() + oneDay, user_id: this.user_id }, meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 7 v: 7,
}, },
{ {
op: [{ i: 'r', p: 8 }], op: [{ i: 'r', p: 8 }],
meta: { ts: Date.now() + oneDay, user_id: this.user_id }, meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 8 v: 8,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -256,14 +256,14 @@ describe('Appending doc ops to the history', function () {
expect(this.updates[0].pack[0].op).to.deep.equal([ expect(this.updates[0].pack[0].op).to.deep.equal([
{ {
p: 3, p: 3,
i: 'foo' i: 'foo',
} },
]) ])
return expect(this.updates[0].pack[1].op).to.deep.equal([ return expect(this.updates[0].pack[1].op).to.deep.equal([
{ {
p: 6, p: 6,
i: 'bar' i: 'bar',
} },
]) ])
}) })
}) })
@ -281,7 +281,7 @@ describe('Appending doc ops to the history', function () {
updates.push({ updates.push({
op: [{ i: 'a', p: 0 }], op: [{ i: 'a', p: 0 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: i v: i,
}) })
this.expectedOp[0].i = `a${this.expectedOp[0].i}` this.expectedOp[0].i = `a${this.expectedOp[0].i}`
} }
@ -290,7 +290,7 @@ describe('Appending doc ops to the history', function () {
this.project_id, this.project_id,
this.doc_id, this.doc_id,
updates, updates,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -334,22 +334,22 @@ describe('Appending doc ops to the history', function () {
op: [ op: [
{ i: 'f', p: 3 }, { i: 'f', p: 3 },
{ i: 'o', p: 4 }, { i: 'o', p: 4 },
{ i: 'o', p: 5 } { i: 'o', p: 5 },
], ],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
}, },
{ {
op: [ op: [
{ i: 'b', p: 6 }, { i: 'b', p: 6 },
{ i: 'a', p: 7 }, { i: 'a', p: 7 },
{ i: 'r', p: 8 } { i: 'r', p: 8 },
], ],
meta: { ts: Date.now() + oneDay, user_id: this.user_id }, meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 4 v: 4,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -373,14 +373,14 @@ describe('Appending doc ops to the history', function () {
expect(this.updates[0].pack[0].op).to.deep.equal([ expect(this.updates[0].pack[0].op).to.deep.equal([
{ {
p: 3, p: 3,
i: 'foo' i: 'foo',
} },
]) ])
return expect(this.updates[0].pack[1].op).to.deep.equal([ return expect(this.updates[0].pack[1].op).to.deep.equal([
{ {
p: 6, p: 6,
i: 'bar' i: 'bar',
} },
]) ])
}) })
@ -404,15 +404,15 @@ describe('Appending doc ops to the history', function () {
{ {
op: [], op: [],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
}, },
{ {
op: [{ i: 'foo', p: 3 }], op: [{ i: 'foo', p: 3 }],
meta: { ts: Date.now() + oneDay, user_id: this.user_id }, meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 4 v: 4,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -440,8 +440,8 @@ describe('Appending doc ops to the history', function () {
return expect(this.updates[0].pack[1].op).to.deep.equal([ return expect(this.updates[0].pack[1].op).to.deep.equal([
{ {
p: 3, p: 3,
i: 'foo' i: 'foo',
} },
]) ])
}) })
@ -464,13 +464,13 @@ describe('Appending doc ops to the history', function () {
{ {
op: [ op: [
{ c: 'foo', p: 3 }, { c: 'foo', p: 3 },
{ d: 'bar', p: 6 } { d: 'bar', p: 6 },
], ],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -492,7 +492,7 @@ describe('Appending doc ops to the history', function () {
it('should ignore the comment op', function () { it('should ignore the comment op', function () {
return expect(this.updates[0].pack[0].op).to.deep.equal([ return expect(this.updates[0].pack[0].op).to.deep.equal([
{ d: 'bar', p: 6 } { d: 'bar', p: 6 },
]) ])
}) })
@ -515,10 +515,10 @@ describe('Appending doc ops to the history', function () {
{ {
op: [{ i: 'f', p: 3 }], op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -557,10 +557,10 @@ describe('Appending doc ops to the history', function () {
{ {
op: [{ i: 'f', p: 3 }], op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }

View file

@ -32,9 +32,9 @@ describe('Archiving updates', function () {
__guard__( __guard__(
__guard__( __guard__(
Settings != null ? Settings.trackchanges : undefined, Settings != null ? Settings.trackchanges : undefined,
(x1) => x1.s3 x1 => x1.s3
), ),
(x) => x.key.length x => x.key.length
) < 1 ) < 1
) { ) {
const message = new Error('s3 keys not setup, this test setup will fail') const message = new Error('s3 keys not setup, this test setup will fail')
@ -57,8 +57,8 @@ describe('Archiving updates', function () {
MockWebApi.projects[this.project_id] = { MockWebApi.projects[this.project_id] = {
features: { features: {
versioning: true versioning: true,
} },
} }
sinon.spy(MockWebApi, 'getProjectDetails') sinon.spy(MockWebApi, 'getProjectDetails')
@ -66,13 +66,13 @@ describe('Archiving updates', function () {
email: 'user@sharelatex.com', email: 'user@sharelatex.com',
first_name: 'Leo', first_name: 'Leo',
last_name: 'Lion', last_name: 'Lion',
id: this.user_id id: this.user_id,
} }
sinon.spy(MockWebApi, 'getUserInfo') sinon.spy(MockWebApi, 'getUserInfo')
MockDocStoreApi.docs[this.doc_id] = this.doc = { MockDocStoreApi.docs[this.doc_id] = this.doc = {
_id: this.doc_id, _id: this.doc_id,
project_id: this.project_id project_id: this.project_id,
} }
sinon.spy(MockDocStoreApi, 'getAllDoc') sinon.spy(MockDocStoreApi, 'getAllDoc')
@ -85,15 +85,15 @@ describe('Archiving updates', function () {
this.updates.push({ this.updates.push({
op: [{ i: 'a', p: 0 }], op: [{ i: 'a', p: 0 }],
meta: { ts: this.now + (i - 2048) * this.hours, user_id: this.user_id }, meta: { ts: this.now + (i - 2048) * this.hours, user_id: this.user_id },
v: 2 * i + 1 v: 2 * i + 1,
}) })
this.updates.push({ this.updates.push({
op: [{ i: 'b', p: 0 }], op: [{ i: 'b', p: 0 }],
meta: { meta: {
ts: this.now + (i - 2048) * this.hours + 10 * this.minutes, ts: this.now + (i - 2048) * this.hours + 10 * this.minutes,
user_id: this.user_id_2 user_id: this.user_id_2,
}, },
v: 2 * i + 2 v: 2 * i + 2,
}) })
} }
TrackChangesApp.ensureRunning(() => { TrackChangesApp.ensureRunning(() => {
@ -101,14 +101,14 @@ describe('Archiving updates', function () {
this.project_id, this.project_id,
this.doc_id, this.doc_id,
this.updates, this.updates,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
return TrackChangesClient.flushDoc( return TrackChangesClient.flushDoc(
this.project_id, this.project_id,
this.doc_id, this.doc_id,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -163,7 +163,7 @@ describe('Archiving updates', function () {
const expectedExportedUpdates = this.updates const expectedExportedUpdates = this.updates
.slice() .slice()
.reverse() .reverse()
.map((update) => { .map(update => {
// clone object, updates are created once in before handler // clone object, updates are created once in before handler
const exportedUpdate = Object.assign({}, update) const exportedUpdate = Object.assign({}, update)
exportedUpdate.meta = Object.assign({}, update.meta) exportedUpdate.meta = Object.assign({}, update.meta)
@ -180,7 +180,7 @@ describe('Archiving updates', function () {
expect(this.exportedUpdates).to.deep.equal(expectedExportedUpdates) expect(this.exportedUpdates).to.deep.equal(expectedExportedUpdates)
expect(this.exportedUserIds).to.deep.equal([ expect(this.exportedUserIds).to.deep.equal([
this.user_id, this.user_id,
this.user_id_2 this.user_id_2,
]) ])
}) })
}) })
@ -192,16 +192,12 @@ describe('Archiving updates', function () {
describe("archiving a doc's updates", function () { describe("archiving a doc's updates", function () {
before(function (done) { before(function (done) {
TrackChangesClient.pushDocHistory( TrackChangesClient.pushDocHistory(this.project_id, this.doc_id, error => {
this.project_id,
this.doc_id,
(error) => {
if (error != null) { if (error != null) {
throw error throw error
} }
return done() return done()
} })
)
return null return null
}) })
@ -222,7 +218,7 @@ describe('Archiving updates', function () {
return db.docHistory.deleteMany( return db.docHistory.deleteMany(
{ {
doc_id: ObjectId(this.doc_id), doc_id: ObjectId(this.doc_id),
expiresAt: { $exists: true } expiresAt: { $exists: true },
}, },
(err, result) => { (err, result) => {
if (typeof error !== 'undefined' && error !== null) { if (typeof error !== 'undefined' && error !== null) {
@ -295,16 +291,12 @@ describe('Archiving updates', function () {
return describe("unarchiving a doc's updates", function () { return describe("unarchiving a doc's updates", function () {
before(function (done) { before(function (done) {
TrackChangesClient.pullDocHistory( TrackChangesClient.pullDocHistory(this.project_id, this.doc_id, error => {
this.project_id,
this.doc_id,
(error) => {
if (error != null) { if (error != null) {
throw error throw error
} }
return done() return done()
} })
)
return null return null
}) })

View file

@ -40,17 +40,17 @@ describe('Flushing updates', function () {
{ {
op: [{ i: 'f', p: 3 }], op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
return TrackChangesClient.flushDoc( return TrackChangesClient.flushDoc(
this.project_id, this.project_id,
this.doc_id, this.doc_id,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -67,8 +67,8 @@ describe('Flushing updates', function () {
expect(updates[0].pack[0].op).to.deep.equal([ expect(updates[0].pack[0].op).to.deep.equal([
{ {
p: 3, p: 3,
i: 'f' i: 'f',
} },
]) ])
return done() return done()
}) })
@ -87,8 +87,8 @@ describe('Flushing updates', function () {
MockWebApi.projects[this.project_id] = { MockWebApi.projects[this.project_id] = {
features: { features: {
versioning: true versioning: true,
} },
} }
TrackChangesClient.pushRawUpdates( TrackChangesClient.pushRawUpdates(
@ -98,19 +98,19 @@ describe('Flushing updates', function () {
{ {
op: [{ i: 'g', p: 2 }], op: [{ i: 'g', p: 2 }],
meta: { ts: Date.now() - 2 * this.weeks, user_id: this.user_id }, meta: { ts: Date.now() - 2 * this.weeks, user_id: this.user_id },
v: 2 v: 2,
}, },
{ {
op: [{ i: 'f', p: 3 }], op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
return TrackChangesClient.flushProject(this.project_id, (error) => { return TrackChangesClient.flushProject(this.project_id, error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -154,8 +154,8 @@ describe('Flushing updates', function () {
MockWebApi.projects[this.project_id] = { MockWebApi.projects[this.project_id] = {
features: { features: {
versioning: false versioning: false,
} },
} }
TrackChangesClient.pushRawUpdates( TrackChangesClient.pushRawUpdates(
@ -165,19 +165,19 @@ describe('Flushing updates', function () {
{ {
op: [{ i: 'g', p: 2 }], op: [{ i: 'g', p: 2 }],
meta: { ts: Date.now() - 2 * this.weeks, user_id: this.user_id }, meta: { ts: Date.now() - 2 * this.weeks, user_id: this.user_id },
v: 2 v: 2,
}, },
{ {
op: [{ i: 'f', p: 3 }], op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
return TrackChangesClient.flushProject(this.project_id, (error) => { return TrackChangesClient.flushProject(this.project_id, error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -210,13 +210,13 @@ describe('Flushing updates', function () {
MockWebApi.projects[this.project_id] = { MockWebApi.projects[this.project_id] = {
features: { features: {
versioning: false versioning: false,
} },
} }
TrackChangesClient.setPreserveHistoryForProject( TrackChangesClient.setPreserveHistoryForProject(
this.project_id, this.project_id,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -228,23 +228,23 @@ describe('Flushing updates', function () {
op: [{ i: 'g', p: 2 }], op: [{ i: 'g', p: 2 }],
meta: { meta: {
ts: Date.now() - 2 * this.weeks, ts: Date.now() - 2 * this.weeks,
user_id: this.user_id user_id: this.user_id,
}, },
v: 2 v: 2,
}, },
{ {
op: [{ i: 'f', p: 3 }], op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id }, meta: { ts: Date.now(), user_id: this.user_id },
v: 3 v: 3,
} },
], ],
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
return TrackChangesClient.flushProject( return TrackChangesClient.flushProject(
this.project_id, this.project_id,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }

View file

@ -35,7 +35,7 @@ describe('Getting a diff', function () {
email: 'user@sharelatex.com', email: 'user@sharelatex.com',
first_name: 'Leo', first_name: 'Leo',
last_name: 'Lion', last_name: 'Lion',
id: this.user_id id: this.user_id,
} }
sinon.spy(MockWebApi, 'getUserInfo') sinon.spy(MockWebApi, 'getUserInfo')
@ -45,23 +45,23 @@ describe('Getting a diff', function () {
{ {
op: [{ i: 'one ', p: 0 }], op: [{ i: 'one ', p: 0 }],
meta: { ts: this.from - twoMinutes, user_id: this.user_id }, meta: { ts: this.from - twoMinutes, user_id: this.user_id },
v: 3 v: 3,
}, },
{ {
op: [{ i: 'two ', p: 4 }], op: [{ i: 'two ', p: 4 }],
meta: { ts: this.from + twoMinutes, user_id: this.user_id }, meta: { ts: this.from + twoMinutes, user_id: this.user_id },
v: (this.fromVersion = 4) v: (this.fromVersion = 4),
}, },
{ {
op: [{ i: 'three ', p: 8 }], op: [{ i: 'three ', p: 8 }],
meta: { ts: this.to - twoMinutes, user_id: this.user_id }, meta: { ts: this.to - twoMinutes, user_id: this.user_id },
v: (this.toVersion = 5) v: (this.toVersion = 5),
}, },
{ {
op: [{ i: 'four', p: 14 }], op: [{ i: 'four', p: 14 }],
meta: { ts: this.to + twoMinutes, user_id: this.user_id }, meta: { ts: this.to + twoMinutes, user_id: this.user_id },
v: 6 v: 6,
} },
] ]
this.lines = ['one two three four'] this.lines = ['one two three four']
this.expected_diff = [ this.expected_diff = [
@ -71,21 +71,21 @@ describe('Getting a diff', function () {
meta: { meta: {
start_ts: this.from + twoMinutes, start_ts: this.from + twoMinutes,
end_ts: this.to - twoMinutes, end_ts: this.to - twoMinutes,
user: this.user user: this.user,
} },
} },
] ]
MockDocUpdaterApi.docs[this.doc_id] = { MockDocUpdaterApi.docs[this.doc_id] = {
lines: this.lines, lines: this.lines,
version: 7 version: 7,
} }
TrackChangesApp.ensureRunning(() => { TrackChangesApp.ensureRunning(() => {
return TrackChangesClient.pushRawUpdates( return TrackChangesClient.pushRawUpdates(
this.project_id, this.project_id,
this.doc_id, this.doc_id,
this.updates, this.updates,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }

View file

@ -33,15 +33,15 @@ describe('Getting updates', function () {
MockWebApi.projects[this.project_id] = { MockWebApi.projects[this.project_id] = {
features: { features: {
versioning: true versioning: true,
} },
} }
MockWebApi.users[this.user_id] = this.user = { MockWebApi.users[this.user_id] = this.user = {
email: 'user@sharelatex.com', email: 'user@sharelatex.com',
first_name: 'Leo', first_name: 'Leo',
last_name: 'Lion', last_name: 'Lion',
id: this.user_id id: this.user_id,
} }
sinon.spy(MockWebApi, 'getUserInfo') sinon.spy(MockWebApi, 'getUserInfo')
@ -51,14 +51,14 @@ describe('Getting updates', function () {
op: [{ i: 'a', p: 0 }], op: [{ i: 'a', p: 0 }],
meta: { meta: {
ts: this.now - (9 - i) * this.hours - 2 * this.minutes, ts: this.now - (9 - i) * this.hours - 2 * this.minutes,
user_id: this.user_id user_id: this.user_id,
}, },
v: 2 * i + 1 v: 2 * i + 1,
}) })
this.updates.push({ this.updates.push({
op: [{ i: 'b', p: 0 }], op: [{ i: 'b', p: 0 }],
meta: { ts: this.now - (9 - i) * this.hours, user_id: this.user_id }, meta: { ts: this.now - (9 - i) * this.hours, user_id: this.user_id },
v: 2 * i + 2 v: 2 * i + 2,
}) })
} }
this.updates[0].meta.user_id = this.deleted_user_id this.updates[0].meta.user_id = this.deleted_user_id
@ -68,7 +68,7 @@ describe('Getting updates', function () {
this.project_id, this.project_id,
this.doc_id, this.doc_id,
this.updates, this.updates,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -82,7 +82,7 @@ describe('Getting updates', function () {
after() { after() {
MockWebApi.getUserInfo.restore() MockWebApi.getUserInfo.restore()
return null return null
} },
}) })
describe('getting updates up to the limit', function () { describe('getting updates up to the limit', function () {
@ -118,25 +118,25 @@ describe('Getting updates', function () {
meta: { meta: {
start_ts: this.to - 2 * this.minutes, start_ts: this.to - 2 * this.minutes,
end_ts: this.to, end_ts: this.to,
users: [this.user] users: [this.user],
} },
}, },
{ {
docs: docs2, docs: docs2,
meta: { meta: {
start_ts: this.to - 1 * this.hours - 2 * this.minutes, start_ts: this.to - 1 * this.hours - 2 * this.minutes,
end_ts: this.to - 1 * this.hours, end_ts: this.to - 1 * this.hours,
users: [this.user] users: [this.user],
} },
}, },
{ {
docs: docs3, docs: docs3,
meta: { meta: {
start_ts: this.to - 2 * this.hours - 2 * this.minutes, start_ts: this.to - 2 * this.hours - 2 * this.minutes,
end_ts: this.to - 2 * this.hours, end_ts: this.to - 2 * this.hours,
users: [this.user] users: [this.user],
} },
} },
]) ])
}) })
}) })
@ -168,17 +168,17 @@ describe('Getting updates', function () {
meta: { meta: {
start_ts: this.to - 8 * this.hours - 2 * this.minutes, start_ts: this.to - 8 * this.hours - 2 * this.minutes,
end_ts: this.to - 8 * this.hours, end_ts: this.to - 8 * this.hours,
users: [this.user] users: [this.user],
} },
}, },
{ {
docs: docs2, docs: docs2,
meta: { meta: {
start_ts: this.to - 9 * this.hours - 2 * this.minutes, start_ts: this.to - 9 * this.hours - 2 * this.minutes,
end_ts: this.to - 9 * this.hours, end_ts: this.to - 9 * this.hours,
users: [this.user, null] users: [this.user, null],
} },
} },
]) ])
}) })
}) })

View file

@ -27,24 +27,24 @@ describe('Locking document', function () {
LockManager.LOCK_TTL = 1 // second LockManager.LOCK_TTL = 1 // second
LockManager.runWithLock( LockManager.runWithLock(
'doc123', 'doc123',
(releaseA) => { releaseA => {
// we create a lock A and allow it to expire in redis // we create a lock A and allow it to expire in redis
return setTimeout( return setTimeout(
() => () =>
// now we create a new lock B and try to release A // now we create a new lock B and try to release A
LockManager.runWithLock( LockManager.runWithLock(
'doc123', 'doc123',
(releaseB) => { releaseB => {
return releaseA() return releaseA()
}, // try to release lock A to see if it wipes out lock B }, // try to release lock A to see if it wipes out lock B
(error) => {} error => {}
), ),
// we never release lock B so nothing should happen here // we never release lock B so nothing should happen here
1500 1500
) )
}, // enough time to wait until the lock has expired }, // enough time to wait until the lock has expired
(error) => error =>
// we get here after trying to release lock A // we get here after trying to release lock A
done() done()
) )

View file

@ -35,23 +35,23 @@ describe('Restoring a version', function () {
{ {
op: [{ i: 'one ', p: 0 }], op: [{ i: 'one ', p: 0 }],
meta: { ts: this.now - 6 * minutes, user_id: this.user_id }, meta: { ts: this.now - 6 * minutes, user_id: this.user_id },
v: 3 v: 3,
}, },
{ {
op: [{ i: 'two ', p: 4 }], op: [{ i: 'two ', p: 4 }],
meta: { ts: this.now - 4 * minutes, user_id: this.user_id }, meta: { ts: this.now - 4 * minutes, user_id: this.user_id },
v: 4 v: 4,
}, },
{ {
op: [{ i: 'three ', p: 8 }], op: [{ i: 'three ', p: 8 }],
meta: { ts: this.now - 2 * minutes, user_id: this.user_id }, meta: { ts: this.now - 2 * minutes, user_id: this.user_id },
v: 5 v: 5,
}, },
{ {
op: [{ i: 'four', p: 14 }], op: [{ i: 'four', p: 14 }],
meta: { ts: this.now, user_id: this.user_id }, meta: { ts: this.now, user_id: this.user_id },
v: 6 v: 6,
} },
] ]
this.lines = ['one two three four'] this.lines = ['one two three four']
this.restored_lines = ['one two '] this.restored_lines = ['one two ']
@ -61,12 +61,12 @@ describe('Restoring a version', function () {
email: 'user@sharelatex.com', email: 'user@sharelatex.com',
first_name: 'Leo', first_name: 'Leo',
last_name: 'Lion', last_name: 'Lion',
id: this.user_id id: this.user_id,
} }
MockDocUpdaterApi.docs[this.doc_id] = { MockDocUpdaterApi.docs[this.doc_id] = {
lines: this.lines, lines: this.lines,
version: 7 version: 7,
} }
TrackChangesApp.ensureRunning(() => { TrackChangesApp.ensureRunning(() => {
@ -74,7 +74,7 @@ describe('Restoring a version', function () {
this.project_id, this.project_id,
this.doc_id, this.doc_id,
this.updates, this.updates,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -83,7 +83,7 @@ describe('Restoring a version', function () {
this.doc_id, this.doc_id,
this.beforeVersion, this.beforeVersion,
this.user_id, this.user_id,
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }

View file

@ -39,16 +39,16 @@ module.exports = MockDocUpdaterApi = {
}) })
return app return app
.listen(3016, (error) => { .listen(3016, error => {
if (error != null) { if (error != null) {
throw error throw error
} }
}) })
.on('error', (error) => { .on('error', error => {
console.error('error starting MockDocStoreApi:', error.message) console.error('error starting MockDocStoreApi:', error.message)
return process.exit(1) return process.exit(1)
}) })
} },
} }
MockDocUpdaterApi.run() MockDocUpdaterApi.run()

View file

@ -74,16 +74,16 @@ module.exports = MockDocUpdaterApi = {
}) })
return app return app
.listen(3003, (error) => { .listen(3003, error => {
if (error != null) { if (error != null) {
throw error throw error
} }
}) })
.on('error', (error) => { .on('error', error => {
console.error('error starting MockDocUpdaterApi:', error.message) console.error('error starting MockDocUpdaterApi:', error.message)
return process.exit(1) return process.exit(1)
}) })
} },
} }
MockDocUpdaterApi.run() MockDocUpdaterApi.run()

View file

@ -61,16 +61,16 @@ module.exports = MockWebApi = {
}) })
return app return app
.listen(3000, (error) => { .listen(3000, error => {
if (error != null) { if (error != null) {
throw error throw error
} }
}) })
.on('error', (error) => { .on('error', error => {
console.error('error starting MockWebApiServer:', error.message) console.error('error starting MockWebApiServer:', error.message)
return process.exit(1) return process.exit(1)
}) })
} },
} }
MockWebApi.run() MockWebApi.run()

View file

@ -38,10 +38,10 @@ module.exports = {
Settings.internal != null Settings.internal != null
? Settings.internal.trackchanges ? Settings.internal.trackchanges
: undefined, : undefined,
(x) => x.port x => x.port
), ),
'localhost', 'localhost',
(error) => { error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -58,7 +58,7 @@ module.exports = {
} }
) )
}) })
} },
} }
function __guard__(value, transform) { function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null return typeof value !== 'undefined' && value !== null

View file

@ -28,7 +28,7 @@ const s3 = new aws.S3({
accessKeyId: Settings.trackchanges.s3.key, accessKeyId: Settings.trackchanges.s3.key,
secretAccessKey: Settings.trackchanges.s3.secret, secretAccessKey: Settings.trackchanges.s3.secret,
endpoint: Settings.trackchanges.s3.endpoint, endpoint: Settings.trackchanges.s3.endpoint,
s3ForcePathStyle: Settings.trackchanges.s3.pathStyle s3ForcePathStyle: Settings.trackchanges.s3.pathStyle,
}) })
const S3_BUCKET = Settings.trackchanges.stores.doc_history const S3_BUCKET = Settings.trackchanges.stores.doc_history
@ -37,7 +37,7 @@ module.exports = TrackChangesClient = {
if (callback == null) { if (callback == null) {
callback = function (error, updates) {} callback = function (error, updates) {}
} }
return TrackChangesClient.flushDoc(project_id, doc_id, (error) => { return TrackChangesClient.flushDoc(project_id, doc_id, error => {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
@ -51,7 +51,7 @@ module.exports = TrackChangesClient = {
} }
return request.post( return request.post(
{ {
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/flush` url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/flush`,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(204) response.statusCode.should.equal(204)
@ -66,7 +66,7 @@ module.exports = TrackChangesClient = {
} }
return request.post( return request.post(
{ {
url: `http://localhost:3015/project/${project_id}/flush` url: `http://localhost:3015/project/${project_id}/flush`,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(204) response.statusCode.should.equal(204)
@ -91,7 +91,7 @@ module.exports = TrackChangesClient = {
} }
return db.projectHistoryMetaData.findOne( return db.projectHistoryMetaData.findOne(
{ {
project_id: ObjectId(project_id) project_id: ObjectId(project_id),
}, },
callback callback
) )
@ -103,13 +103,13 @@ module.exports = TrackChangesClient = {
} }
return db.projectHistoryMetaData.updateOne( return db.projectHistoryMetaData.updateOne(
{ {
project_id: ObjectId(project_id) project_id: ObjectId(project_id),
}, },
{ {
$set: { preserveHistory: true } $set: { preserveHistory: true },
}, },
{ {
upsert: true upsert: true,
}, },
callback callback
) )
@ -122,13 +122,13 @@ module.exports = TrackChangesClient = {
return rclient.sadd( return rclient.sadd(
Keys.docsWithHistoryOps({ project_id }), Keys.docsWithHistoryOps({ project_id }),
doc_id, doc_id,
(error) => { error => {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return rclient.rpush( return rclient.rpush(
Keys.uncompressedHistoryOps({ doc_id }), Keys.uncompressedHistoryOps({ doc_id }),
...Array.from(Array.from(updates).map((u) => JSON.stringify(u))), ...Array.from(Array.from(updates).map(u => JSON.stringify(u))),
callback callback
) )
} }
@ -141,7 +141,7 @@ module.exports = TrackChangesClient = {
} }
return request.get( return request.get(
{ {
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/diff?from=${from}&to=${to}` url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/diff?from=${from}&to=${to}`,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(200) response.statusCode.should.equal(200)
@ -156,7 +156,7 @@ module.exports = TrackChangesClient = {
} }
return request.get( return request.get(
{ {
url: `http://localhost:3015/project/${project_id}/updates?before=${options.before}&min_count=${options.min_count}` url: `http://localhost:3015/project/${project_id}/updates?before=${options.before}&min_count=${options.min_count}`,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(200) response.statusCode.should.equal(200)
@ -184,8 +184,8 @@ module.exports = TrackChangesClient = {
{ {
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/version/${version}/restore`, url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/version/${version}/restore`,
headers: { headers: {
'X-User-Id': user_id 'X-User-Id': user_id,
} },
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(204) response.statusCode.should.equal(204)
@ -200,7 +200,7 @@ module.exports = TrackChangesClient = {
} }
return request.post( return request.post(
{ {
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/push` url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/push`,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(204) response.statusCode.should.equal(204)
@ -215,7 +215,7 @@ module.exports = TrackChangesClient = {
} }
return request.post( return request.post(
{ {
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/pull` url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/pull`,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(204) response.statusCode.should.equal(204)
@ -254,7 +254,7 @@ module.exports = TrackChangesClient = {
} }
const params = { const params = {
Bucket: S3_BUCKET, Bucket: S3_BUCKET,
Key: `${project_id}/changes-${doc_id}/pack-${pack_id}` Key: `${project_id}/changes-${doc_id}/pack-${pack_id}`,
} }
return s3.getObject(params, (error, data) => { return s3.getObject(params, (error, data) => {
@ -280,7 +280,7 @@ module.exports = TrackChangesClient = {
} }
let params = { let params = {
Bucket: S3_BUCKET, Bucket: S3_BUCKET,
Prefix: `${project_id}/changes-${doc_id}` Prefix: `${project_id}/changes-${doc_id}`,
} }
return s3.listObjects(params, (error, data) => { return s3.listObjects(params, (error, data) => {
@ -291,11 +291,11 @@ module.exports = TrackChangesClient = {
params = { params = {
Bucket: S3_BUCKET, Bucket: S3_BUCKET,
Delete: { Delete: {
Objects: data.Contents.map((s3object) => ({ Key: s3object.Key })) Objects: data.Contents.map(s3object => ({ Key: s3object.Key })),
} },
} }
return s3.deleteObjects(params, callback) return s3.deleteObjects(params, callback)
}) })
} },
} }

View file

@ -14,8 +14,8 @@ SandboxedModule.configure({
warn() {}, warn() {},
err() {}, err() {},
error() {}, error() {},
fatal() {} fatal() {},
}
}, },
globals: { Buffer, JSON, console, process } },
globals: { Buffer, JSON, console, process },
}) })

View file

@ -24,7 +24,7 @@ describe('DiffGenerator', function () {
return (this.meta = { return (this.meta = {
start_ts: this.ts, start_ts: this.ts,
end_ts: this.ts, end_ts: this.ts,
user_id: this.user_id user_id: this.user_id,
}) })
}) })
@ -34,7 +34,7 @@ describe('DiffGenerator', function () {
const content = 'hello world' const content = 'hello world'
const rewoundContent = this.DiffGenerator.rewindOp(content, { const rewoundContent = this.DiffGenerator.rewindOp(content, {
p: 6, p: 6,
i: 'wo' i: 'wo',
}) })
return rewoundContent.should.equal('hello rld') return rewoundContent.should.equal('hello rld')
}) })
@ -45,7 +45,7 @@ describe('DiffGenerator', function () {
const content = 'hello rld' const content = 'hello rld'
const rewoundContent = this.DiffGenerator.rewindOp(content, { const rewoundContent = this.DiffGenerator.rewindOp(content, {
p: 6, p: 6,
d: 'wo' d: 'wo',
}) })
return rewoundContent.should.equal('hello world') return rewoundContent.should.equal('hello world')
}) })
@ -65,7 +65,7 @@ describe('DiffGenerator', function () {
const content = 'foobar' const content = 'foobar'
const rewoundContent = this.DiffGenerator.rewindOp(content, { const rewoundContent = this.DiffGenerator.rewindOp(content, {
p: 4, p: 4,
i: 'bar' i: 'bar',
}) })
return rewoundContent.should.equal('foo') return rewoundContent.should.equal('foo')
}) })
@ -78,8 +78,8 @@ describe('DiffGenerator', function () {
const update = { const update = {
op: [ op: [
{ p: 3, i: 'bbb' }, { p: 3, i: 'bbb' },
{ p: 6, i: 'ccc' } { p: 6, i: 'ccc' },
] ],
} }
const rewoundContent = this.DiffGenerator.rewindUpdate(content, update) const rewoundContent = this.DiffGenerator.rewindUpdate(content, update)
return rewoundContent.should.equal('aaa') return rewoundContent.should.equal('aaa')
@ -91,7 +91,7 @@ describe('DiffGenerator', function () {
const content = 'aaabbbccc' const content = 'aaabbbccc'
const updates = [ const updates = [
{ op: [{ p: 3, i: 'bbb' }] }, { op: [{ p: 3, i: 'bbb' }] },
{ op: [{ p: 6, i: 'ccc' }] } { op: [{ p: 6, i: 'ccc' }] },
] ]
const rewoundContent = this.DiffGenerator.rewindUpdates(content, updates) const rewoundContent = this.DiffGenerator.rewindUpdates(content, updates)
return rewoundContent.should.equal('aaa') return rewoundContent.should.equal('aaa')
@ -105,7 +105,7 @@ describe('DiffGenerator', function () {
this.updates = [ this.updates = [
{ i: 'mock-update-1' }, { i: 'mock-update-1' },
{ i: 'mock-update-2' }, { i: 'mock-update-2' },
{ i: 'mock-update-3' } { i: 'mock-update-3' },
] ]
this.DiffGenerator.applyUpdateToDiff = sinon.stub().returns(this.diff) this.DiffGenerator.applyUpdateToDiff = sinon.stub().returns(this.diff)
this.DiffGenerator.compressDiff = sinon.stub().returns(this.diff) this.DiffGenerator.compressDiff = sinon.stub().returns(this.diff)
@ -124,8 +124,8 @@ describe('DiffGenerator', function () {
.calledWith( .calledWith(
[ [
{ {
u: this.content u: this.content,
} },
], ],
this.updates[0] this.updates[0]
) )
@ -133,7 +133,7 @@ describe('DiffGenerator', function () {
}) })
it('should apply each update', function () { it('should apply each update', function () {
return Array.from(this.updates).map((update) => return Array.from(this.updates).map(update =>
this.DiffGenerator.applyUpdateToDiff this.DiffGenerator.applyUpdateToDiff
.calledWith(sinon.match.any, update) .calledWith(sinon.match.any, update)
.should.equal(true) .should.equal(true)
@ -153,18 +153,18 @@ describe('DiffGenerator', function () {
const diff = this.DiffGenerator.compressDiff([ const diff = this.DiffGenerator.compressDiff([
{ {
i: 'foo', i: 'foo',
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } } meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } },
}, },
{ {
i: 'bar', i: 'bar',
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id } } meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id } },
} },
]) ])
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ {
i: 'foobar', i: 'foobar',
meta: { start_ts: 5, end_ts: 20, user: { id: this.user_id } } meta: { start_ts: 5, end_ts: 20, user: { id: this.user_id } },
} },
]) ])
}) })
}) })
@ -174,12 +174,12 @@ describe('DiffGenerator', function () {
const input = [ const input = [
{ {
i: 'foo', i: 'foo',
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } } meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } },
}, },
{ {
i: 'bar', i: 'bar',
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id_2 } } meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id_2 } },
} },
] ]
const output = this.DiffGenerator.compressDiff(input) const output = this.DiffGenerator.compressDiff(input)
return expect(output).to.deep.equal(input) return expect(output).to.deep.equal(input)
@ -191,18 +191,18 @@ describe('DiffGenerator', function () {
const diff = this.DiffGenerator.compressDiff([ const diff = this.DiffGenerator.compressDiff([
{ {
d: 'foo', d: 'foo',
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } } meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } },
}, },
{ {
d: 'bar', d: 'bar',
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id } } meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id } },
} },
]) ])
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ {
d: 'foobar', d: 'foobar',
meta: { start_ts: 5, end_ts: 20, user: { id: this.user_id } } meta: { start_ts: 5, end_ts: 20, user: { id: this.user_id } },
} },
]) ])
}) })
}) })
@ -212,12 +212,12 @@ describe('DiffGenerator', function () {
const input = [ const input = [
{ {
d: 'foo', d: 'foo',
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } } meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } },
}, },
{ {
d: 'bar', d: 'bar',
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id_2 } } meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id_2 } },
} },
] ]
const output = this.DiffGenerator.compressDiff(input) const output = this.DiffGenerator.compressDiff(input)
return expect(output).to.deep.equal(input) return expect(output).to.deep.equal(input)
@ -230,34 +230,34 @@ describe('DiffGenerator', function () {
it('should insert into the middle of (u)nchanged text', function () { it('should insert into the middle of (u)nchanged text', function () {
const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], { const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
op: [{ p: 3, i: 'baz' }], op: [{ p: 3, i: 'baz' }],
meta: this.meta meta: this.meta,
}) })
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ u: 'foo' }, { u: 'foo' },
{ i: 'baz', meta: this.meta }, { i: 'baz', meta: this.meta },
{ u: 'bar' } { u: 'bar' },
]) ])
}) })
it('should insert into the start of (u)changed text', function () { it('should insert into the start of (u)changed text', function () {
const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], { const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
op: [{ p: 0, i: 'baz' }], op: [{ p: 0, i: 'baz' }],
meta: this.meta meta: this.meta,
}) })
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ i: 'baz', meta: this.meta }, { i: 'baz', meta: this.meta },
{ u: 'foobar' } { u: 'foobar' },
]) ])
}) })
it('should insert into the end of (u)changed text', function () { it('should insert into the end of (u)changed text', function () {
const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], { const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
op: [{ p: 6, i: 'baz' }], op: [{ p: 6, i: 'baz' }],
meta: this.meta meta: this.meta,
}) })
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ u: 'foobar' }, { u: 'foobar' },
{ i: 'baz', meta: this.meta } { i: 'baz', meta: this.meta },
]) ])
}) })
@ -269,7 +269,7 @@ describe('DiffGenerator', function () {
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ i: 'foo', meta: this.meta }, { i: 'foo', meta: this.meta },
{ i: 'baz', meta: this.meta }, { i: 'baz', meta: this.meta },
{ i: 'bar', meta: this.meta } { i: 'bar', meta: this.meta },
]) ])
}) })
@ -282,7 +282,7 @@ describe('DiffGenerator', function () {
{ d: 'deleted', meta: this.meta }, { d: 'deleted', meta: this.meta },
{ u: 'foo' }, { u: 'foo' },
{ i: 'baz', meta: this.meta }, { i: 'baz', meta: this.meta },
{ u: 'bar' } { u: 'bar' },
]) ])
}) })
}) })
@ -297,7 +297,7 @@ describe('DiffGenerator', function () {
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ u: 'foo' }, { u: 'foo' },
{ d: 'baz', meta: this.meta }, { d: 'baz', meta: this.meta },
{ u: 'bar' } { u: 'bar' },
]) ])
}) })
@ -308,7 +308,7 @@ describe('DiffGenerator', function () {
) )
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ d: 'foo', meta: this.meta }, { d: 'foo', meta: this.meta },
{ u: 'bazbar' } { u: 'bazbar' },
]) ])
}) })
@ -319,7 +319,7 @@ describe('DiffGenerator', function () {
) )
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ u: 'foobaz' }, { u: 'foobaz' },
{ d: 'bar', meta: this.meta } { d: 'bar', meta: this.meta },
]) ])
}) })
@ -333,7 +333,7 @@ describe('DiffGenerator', function () {
{ d: 'o', meta: this.meta }, { d: 'o', meta: this.meta },
{ d: 'baz', meta: this.meta }, { d: 'baz', meta: this.meta },
{ d: 'b', meta: this.meta }, { d: 'b', meta: this.meta },
{ u: 'ar' } { u: 'ar' },
]) ])
}) })
}) })
@ -346,7 +346,7 @@ describe('DiffGenerator', function () {
) )
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ i: 'foo', meta: this.meta }, { i: 'foo', meta: this.meta },
{ i: 'bar', meta: this.meta } { i: 'bar', meta: this.meta },
]) ])
}) })
@ -375,7 +375,7 @@ describe('DiffGenerator', function () {
{ u: 'fo' }, { u: 'fo' },
{ d: 'o', meta: this.meta }, { d: 'o', meta: this.meta },
{ d: 'b', meta: this.meta }, { d: 'b', meta: this.meta },
{ u: 'ar' } { u: 'ar' },
]) ])
}) })
}) })
@ -391,7 +391,7 @@ describe('DiffGenerator', function () {
{ d: 'o', meta: this.meta }, { d: 'o', meta: this.meta },
{ d: 'baz', meta: this.meta }, { d: 'baz', meta: this.meta },
{ d: 'b', meta: this.meta }, { d: 'b', meta: this.meta },
{ u: 'ar' } { u: 'ar' },
]) ])
}) })
}) })
@ -401,7 +401,7 @@ describe('DiffGenerator', function () {
return expect(() => return expect(() =>
this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], { this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
op: [{ p: 3, d: 'xxx' }], op: [{ p: 3, d: 'xxx' }],
meta: this.meta meta: this.meta,
}) })
).to.throw(this.DiffGenerator.ConsistencyError) ).to.throw(this.DiffGenerator.ConsistencyError)
}) })
@ -410,7 +410,7 @@ describe('DiffGenerator', function () {
return expect(() => return expect(() =>
this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], { this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
op: [{ p: 0, d: 'xxx' }], op: [{ p: 0, d: 'xxx' }],
meta: this.meta meta: this.meta,
}) })
).to.throw(this.DiffGenerator.ConsistencyError) ).to.throw(this.DiffGenerator.ConsistencyError)
}) })
@ -419,7 +419,7 @@ describe('DiffGenerator', function () {
return expect(() => return expect(() =>
this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], { this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
op: [{ p: 6, d: 'xxx' }], op: [{ p: 6, d: 'xxx' }],
meta: this.meta meta: this.meta,
}) })
).to.throw(this.DiffGenerator.ConsistencyError) ).to.throw(this.DiffGenerator.ConsistencyError)
}) })
@ -434,7 +434,7 @@ describe('DiffGenerator', function () {
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ u: 'foo' }, { u: 'foo' },
{ i: 'baz', meta: this.meta }, { i: 'baz', meta: this.meta },
{ d: 'bar', meta: this.meta } { d: 'bar', meta: this.meta },
]) ])
}) })
}) })
@ -447,7 +447,7 @@ describe('DiffGenerator', function () {
) )
return expect(diff).to.deep.equal([ return expect(diff).to.deep.equal([
{ d: 'bar', meta: this.meta }, { d: 'bar', meta: this.meta },
{ i: 'baz', meta: this.meta } { i: 'baz', meta: this.meta },
]) ])
}) })
}) })

View file

@ -21,8 +21,8 @@ describe('DiffManager', function () {
requires: { requires: {
'./UpdatesManager': (this.UpdatesManager = {}), './UpdatesManager': (this.UpdatesManager = {}),
'./DocumentUpdaterManager': (this.DocumentUpdaterManager = {}), './DocumentUpdaterManager': (this.DocumentUpdaterManager = {}),
'./DiffGenerator': (this.DiffGenerator = {}) './DiffGenerator': (this.DiffGenerator = {}),
} },
}) })
this.callback = sinon.stub() this.callback = sinon.stub()
this.from = new Date() this.from = new Date()
@ -114,23 +114,23 @@ describe('DiffManager', function () {
{ {
op: 'mock-4', op: 'mock-4',
v: 42, v: 42,
meta: { start_ts: new Date(this.to.getTime() + 20) } meta: { start_ts: new Date(this.to.getTime() + 20) },
}, },
{ {
op: 'mock-3', op: 'mock-3',
v: 41, v: 41,
meta: { start_ts: new Date(this.to.getTime() + 10) } meta: { start_ts: new Date(this.to.getTime() + 10) },
}, },
{ {
op: 'mock-2', op: 'mock-2',
v: 40, v: 40,
meta: { start_ts: new Date(this.to.getTime() - 10) } meta: { start_ts: new Date(this.to.getTime() - 10) },
}, },
{ {
op: 'mock-1', op: 'mock-1',
v: 39, v: 39,
meta: { start_ts: new Date(this.to.getTime() - 20) } meta: { start_ts: new Date(this.to.getTime() - 20) },
} },
] ]
this.fromVersion = 39 this.fromVersion = 39
this.toVersion = 40 this.toVersion = 40
@ -333,23 +333,23 @@ describe('DiffManager', function () {
{ {
op: 'mock-4', op: 'mock-4',
v: 42, v: 42,
meta: { start_ts: new Date(this.to.getTime() + 20) } meta: { start_ts: new Date(this.to.getTime() + 20) },
}, },
{ {
op: 'mock-3', op: 'mock-3',
v: 41, v: 41,
meta: { start_ts: new Date(this.to.getTime() + 10) } meta: { start_ts: new Date(this.to.getTime() + 10) },
}, },
{ {
op: 'mock-2', op: 'mock-2',
v: 40, v: 40,
meta: { start_ts: new Date(this.to.getTime() - 10) } meta: { start_ts: new Date(this.to.getTime() - 10) },
}, },
{ {
op: 'mock-1', op: 'mock-1',
v: 39, v: 39,
meta: { start_ts: new Date(this.to.getTime() - 20) } meta: { start_ts: new Date(this.to.getTime() - 20) },
} },
] ]
this.fromVersion = 39 this.fromVersion = 39
this.rewound_content = 'rewound-content' this.rewound_content = 'rewound-content'
@ -400,7 +400,7 @@ describe('DiffManager', function () {
this.version = 50 this.version = 50
this.updates = [ this.updates = [
{ op: 'mock-1', v: 40 }, { op: 'mock-1', v: 40 },
{ op: 'mock-1', v: 39 } { op: 'mock-1', v: 39 },
] ]
this.DiffManager.getLatestDocAndUpdates = sinon this.DiffManager.getLatestDocAndUpdates = sinon
.stub() .stub()

View file

@ -25,12 +25,12 @@ describe('MongoAWS', function () {
trackchanges: { trackchanges: {
s3: { s3: {
secret: 's3-secret', secret: 's3-secret',
key: 's3-key' key: 's3-key',
}, },
stores: { stores: {
doc_history: 's3-bucket' doc_history: 's3-bucket',
} },
} },
}), }),
child_process: (this.child_process = {}), child_process: (this.child_process = {}),
'mongo-uri': (this.mongouri = {}), 'mongo-uri': (this.mongouri = {}),
@ -40,8 +40,8 @@ describe('MongoAWS', function () {
'./mongodb': { db: (this.db = {}), ObjectId }, './mongodb': { db: (this.db = {}), ObjectId },
JSONStream: (this.JSONStream = {}), JSONStream: (this.JSONStream = {}),
'readline-stream': (this.readline = sinon.stub()), 'readline-stream': (this.readline = sinon.stub()),
'@overleaf/metrics': { inc() {} } '@overleaf/metrics': { inc() {} },
} },
}) })
this.project_id = ObjectId().toString() this.project_id = ObjectId().toString()

View file

@ -20,9 +20,9 @@ describe('DocumentUpdaterManager', function () {
requires: { requires: {
request: (this.request = {}), request: (this.request = {}),
'@overleaf/settings': (this.settings = { '@overleaf/settings': (this.settings = {
apis: { documentupdater: { url: 'http://example.com' } } apis: { documentupdater: { url: 'http://example.com' } },
}) }),
} },
}) })
this.callback = sinon.stub() this.callback = sinon.stub()
this.lines = ['one', 'two', 'three'] this.lines = ['one', 'two', 'three']
@ -35,7 +35,7 @@ describe('DocumentUpdaterManager', function () {
this.body = JSON.stringify({ this.body = JSON.stringify({
lines: this.lines, lines: this.lines,
version: this.version, version: this.version,
ops: [] ops: [],
}) })
this.request.get = sinon this.request.get = sinon
.stub() .stub()
@ -135,8 +135,8 @@ describe('DocumentUpdaterManager', function () {
lines: this.content.split('\n'), lines: this.content.split('\n'),
source: 'restore', source: 'restore',
user_id: this.user_id, user_id: this.user_id,
undoing: true undoing: true,
} },
}) })
.should.equal(true) .should.equal(true)
}) })

View file

@ -24,8 +24,8 @@ describe('HttpController', function () {
'./RestoreManager': (this.RestoreManager = {}), './RestoreManager': (this.RestoreManager = {}),
'./PackManager': (this.PackManager = {}), './PackManager': (this.PackManager = {}),
'./DocArchiveManager': (this.DocArchiveManager = {}), './DocArchiveManager': (this.DocArchiveManager = {}),
'./HealthChecker': (this.HealthChecker = {}) './HealthChecker': (this.HealthChecker = {}),
} },
}) })
this.doc_id = 'doc-id-123' this.doc_id = 'doc-id-123'
this.project_id = 'project-id-123' this.project_id = 'project-id-123'
@ -39,8 +39,8 @@ describe('HttpController', function () {
this.req = { this.req = {
params: { params: {
doc_id: this.doc_id, doc_id: this.doc_id,
project_id: this.project_id project_id: this.project_id,
} },
} }
this.res = { sendStatus: sinon.stub() } this.res = { sendStatus: sinon.stub() }
this.UpdatesManager.processUncompressedUpdatesWithLock = sinon this.UpdatesManager.processUncompressedUpdatesWithLock = sinon
@ -64,8 +64,8 @@ describe('HttpController', function () {
beforeEach(function () { beforeEach(function () {
this.req = { this.req = {
params: { params: {
project_id: this.project_id project_id: this.project_id,
} },
} }
this.res = { sendStatus: sinon.stub() } this.res = { sendStatus: sinon.stub() }
this.UpdatesManager.processUncompressedUpdatesForProject = sinon this.UpdatesManager.processUncompressedUpdatesForProject = sinon
@ -92,12 +92,12 @@ describe('HttpController', function () {
this.req = { this.req = {
params: { params: {
doc_id: this.doc_id, doc_id: this.doc_id,
project_id: this.project_id project_id: this.project_id,
}, },
query: { query: {
from: this.from.toString(), from: this.from.toString(),
to: this.to.toString() to: this.to.toString(),
} },
} }
this.res = { json: sinon.stub() } this.res = { json: sinon.stub() }
this.diff = [{ u: 'mock-diff' }] this.diff = [{ u: 'mock-diff' }]
@ -128,12 +128,12 @@ describe('HttpController', function () {
this.min_count = 10 this.min_count = 10
this.req = { this.req = {
params: { params: {
project_id: this.project_id project_id: this.project_id,
}, },
query: { query: {
before: this.before.toString(), before: this.before.toString(),
min_count: this.min_count.toString() min_count: this.min_count.toString(),
} },
} }
this.res = { json: sinon.stub() } this.res = { json: sinon.stub() }
this.updates = ['mock-summarized-updates'] this.updates = ['mock-summarized-updates']
@ -147,7 +147,7 @@ describe('HttpController', function () {
return this.UpdatesManager.getSummarizedProjectUpdates return this.UpdatesManager.getSummarizedProjectUpdates
.calledWith(this.project_id, { .calledWith(this.project_id, {
before: this.before, before: this.before,
min_count: this.min_count min_count: this.min_count,
}) })
.should.equal(true) .should.equal(true)
}) })
@ -156,7 +156,7 @@ describe('HttpController', function () {
return this.res.json return this.res.json
.calledWith({ .calledWith({
updates: this.updates, updates: this.updates,
nextBeforeTimestamp: this.nextBeforeTimestamp nextBeforeTimestamp: this.nextBeforeTimestamp,
}) })
.should.equal(true) .should.equal(true)
}) })
@ -169,11 +169,11 @@ describe('HttpController', function () {
params: { params: {
doc_id: this.doc_id, doc_id: this.doc_id,
project_id: this.project_id, project_id: this.project_id,
version: this.version version: this.version,
}, },
headers: { headers: {
'x-user-id': this.user_id 'x-user-id': this.user_id,
} },
} }
this.res = { sendStatus: sinon.stub() } this.res = { sendStatus: sinon.stub() }

View file

@ -24,18 +24,18 @@ describe('LockManager', function () {
beforeEach(function () { beforeEach(function () {
this.Settings = { this.Settings = {
redis: { redis: {
lock: {} lock: {},
} },
} }
this.LockManager = SandboxedModule.require(modulePath, { this.LockManager = SandboxedModule.require(modulePath, {
requires: { requires: {
'@overleaf/redis-wrapper': { '@overleaf/redis-wrapper': {
createClient: () => { createClient: () => {
return (this.rclient = { auth: sinon.stub() }) return (this.rclient = { auth: sinon.stub() })
}
}, },
'@overleaf/settings': this.Settings },
} '@overleaf/settings': this.Settings,
},
}) })
this.key = 'lock-key' this.key = 'lock-key'
@ -240,7 +240,7 @@ describe('LockManager', function () {
describe('when the runner function returns an error', function () { describe('when the runner function returns an error', function () {
beforeEach(function () { beforeEach(function () {
this.error = new Error('oops') this.error = new Error('oops')
this.runner = (releaseLock) => { this.runner = releaseLock => {
if (releaseLock == null) { if (releaseLock == null) {
releaseLock = function (error) {} releaseLock = function (error) {}
} }

View file

@ -24,8 +24,8 @@ describe('MongoManager', function () {
requires: { requires: {
'./mongodb': { db: (this.db = {}), ObjectId }, './mongodb': { db: (this.db = {}), ObjectId },
'./PackManager': (this.PackManager = {}), './PackManager': (this.PackManager = {}),
'@overleaf/metrics': { timeAsyncMethod() {} } '@overleaf/metrics': { timeAsyncMethod() {} },
} },
}) })
this.callback = sinon.stub() this.callback = sinon.stub()
this.doc_id = ObjectId().toString() this.doc_id = ObjectId().toString()
@ -166,10 +166,10 @@ describe('MongoManager', function () {
.calledWith( .calledWith(
{ {
doc_id: ObjectId(this.doc_id), doc_id: ObjectId(this.doc_id),
project_id: { $exists: false } project_id: { $exists: false },
}, },
{ {
$set: { project_id: ObjectId(this.project_id) } $set: { project_id: ObjectId(this.project_id) },
} }
) )
.should.equal(true) .should.equal(true)
@ -184,7 +184,7 @@ describe('MongoManager', function () {
beforeEach(function () { beforeEach(function () {
this.metadata = { mock: 'metadata' } this.metadata = { mock: 'metadata' }
this.db.projectHistoryMetaData = { this.db.projectHistoryMetaData = {
findOne: sinon.stub().callsArgWith(1, null, this.metadata) findOne: sinon.stub().callsArgWith(1, null, this.metadata),
} }
return this.MongoManager.getProjectMetaData( return this.MongoManager.getProjectMetaData(
this.project_id, this.project_id,
@ -207,7 +207,7 @@ describe('MongoManager', function () {
beforeEach(function () { beforeEach(function () {
this.metadata = { mock: 'metadata' } this.metadata = { mock: 'metadata' }
this.db.projectHistoryMetaData = { this.db.projectHistoryMetaData = {
updateOne: sinon.stub().yields() updateOne: sinon.stub().yields(),
} }
return this.MongoManager.setProjectMetaData( return this.MongoManager.setProjectMetaData(
this.project_id, this.project_id,
@ -220,13 +220,13 @@ describe('MongoManager', function () {
return this.db.projectHistoryMetaData.updateOne return this.db.projectHistoryMetaData.updateOne
.calledWith( .calledWith(
{ {
project_id: ObjectId(this.project_id) project_id: ObjectId(this.project_id),
}, },
{ {
$set: this.metadata $set: this.metadata,
}, },
{ {
upsert: true upsert: true,
} }
) )
.should.equal(true) .should.equal(true)

View file

@ -31,9 +31,9 @@ describe('PackManager', function () {
'@overleaf/metrics': { inc() {} }, '@overleaf/metrics': { inc() {} },
'./ProjectIterator': require('../../../../app/js/ProjectIterator.js'), // Cache for speed './ProjectIterator': require('../../../../app/js/ProjectIterator.js'), // Cache for speed
'@overleaf/settings': { '@overleaf/settings': {
redis: { lock: { key_schema: {} } } redis: { lock: { key_schema: {} } },
} },
} },
}) })
this.callback = sinon.stub() this.callback = sinon.stub()
this.doc_id = ObjectId().toString() this.doc_id = ObjectId().toString()
@ -51,20 +51,20 @@ describe('PackManager', function () {
_id: '12345', _id: '12345',
pack: [ pack: [
{ op: 'op-1', meta: 'meta-1', v: 1 }, { op: 'op-1', meta: 'meta-1', v: 1 },
{ op: 'op-2', meta: 'meta-2', v: 2 } { op: 'op-2', meta: 'meta-2', v: 2 },
], ],
n: 2, n: 2,
sz: 100 sz: 100,
} }
this.newUpdates = [ this.newUpdates = [
{ op: 'op-3', meta: 'meta-3', v: 3 }, { op: 'op-3', meta: 'meta-3', v: 3 },
{ op: 'op-4', meta: 'meta-4', v: 4 } { op: 'op-4', meta: 'meta-4', v: 4 },
] ]
return (this.db.docHistory = { return (this.db.docHistory = {
insertOne: sinon.stub().yields(), insertOne: sinon.stub().yields(),
insert: sinon.stub().callsArg(1), insert: sinon.stub().callsArg(1),
updateOne: sinon.stub().yields(), updateOne: sinon.stub().yields(),
findAndModify: sinon.stub().callsArg(1) findAndModify: sinon.stub().callsArg(1),
}) })
}) })
@ -95,10 +95,10 @@ describe('PackManager', function () {
return describe('for many small updates', function () { return describe('for many small updates', function () {
beforeEach(function () { beforeEach(function () {
this.newUpdates = __range__(0, 2048, true).map((i) => ({ this.newUpdates = __range__(0, 2048, true).map(i => ({
op: `op-${i}`, op: `op-${i}`,
meta: `meta-${i}`, meta: `meta-${i}`,
v: i v: i,
})) }))
return this.PackManager.insertCompressedUpdates( return this.PackManager.insertCompressedUpdates(
this.project_id, this.project_id,
@ -209,10 +209,10 @@ describe('PackManager', function () {
describe('for many small updates', function () { describe('for many small updates', function () {
beforeEach(function () { beforeEach(function () {
this.newUpdates = __range__(0, 2048, true).map((i) => ({ this.newUpdates = __range__(0, 2048, true).map(i => ({
op: `op-${i}`, op: `op-${i}`,
meta: `meta-${i}`, meta: `meta-${i}`,
v: i v: i,
})) }))
return this.PackManager.insertCompressedUpdates( return this.PackManager.insertCompressedUpdates(
this.project_id, this.project_id,
@ -292,12 +292,12 @@ describe('PackManager', function () {
0.75 * this.PackManager.MAX_SIZE, 0.75 * this.PackManager.MAX_SIZE,
true true
) )
.map((j) => 'a') .map(j => 'a')
.join('') .join('')
this.newUpdates = [0, 1, 2, 3, 4].map((i) => ({ this.newUpdates = [0, 1, 2, 3, 4].map(i => ({
op: `op-${i}-${longString}`, op: `op-${i}-${longString}`,
meta: `meta-${i}`, meta: `meta-${i}`,
v: i v: i,
})) }))
return this.PackManager.insertCompressedUpdates( return this.PackManager.insertCompressedUpdates(
this.project_id, this.project_id,
@ -393,7 +393,7 @@ describe('PackManager', function () {
doc_id: ObjectId(this.doc_id), doc_id: ObjectId(this.doc_id),
n: this.newUpdates.length, n: this.newUpdates.length,
v: this.newUpdates[0].v, v: this.newUpdates[0].v,
v_end: this.newUpdates[this.newUpdates.length - 1].v v_end: this.newUpdates[this.newUpdates.length - 1].v,
}) })
.should.equal(true) .should.equal(true)
}) })
@ -401,7 +401,7 @@ describe('PackManager', function () {
it('should set an expiry time in the future', function () { it('should set an expiry time in the future', function () {
return this.db.docHistory.insertOne return this.db.docHistory.insertOne
.calledWithMatch({ .calledWithMatch({
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000) expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000),
}) })
.should.equal(true) .should.equal(true)
}) })
@ -419,12 +419,12 @@ describe('PackManager', function () {
_id: '12345', _id: '12345',
pack: [ pack: [
{ op: 'op-1', meta: 'meta-1', v: 1 }, { op: 'op-1', meta: 'meta-1', v: 1 },
{ op: 'op-2', meta: 'meta-2', v: 2 } { op: 'op-2', meta: 'meta-2', v: 2 },
], ],
n: 2, n: 2,
sz: 100, sz: 100,
meta: { start_ts: Date.now() - 6 * 3600 * 1000 }, meta: { start_ts: Date.now() - 6 * 3600 * 1000 },
expiresAt: new Date(Date.now()) expiresAt: new Date(Date.now()),
} }
return this.PackManager.flushCompressedUpdates( return this.PackManager.flushCompressedUpdates(
@ -444,7 +444,7 @@ describe('PackManager', function () {
{ _id: this.lastUpdate._id }, { _id: this.lastUpdate._id },
{ {
$push: { pack: { $each: this.newUpdates } }, $push: { pack: { $each: this.newUpdates } },
$set: { v_end: this.newUpdates[this.newUpdates.length - 1].v } $set: { v_end: this.newUpdates[this.newUpdates.length - 1].v },
} }
) )
.should.equal(true) .should.equal(true)
@ -453,7 +453,7 @@ describe('PackManager', function () {
it('should set an expiry time in the future', function () { it('should set an expiry time in the future', function () {
return this.db.docHistory.updateOne return this.db.docHistory.updateOne
.calledWithMatch(sinon.match.any, { .calledWithMatch(sinon.match.any, {
$set: { expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000) } $set: { expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000) },
}) })
.should.equal(true) .should.equal(true)
}) })
@ -472,12 +472,12 @@ describe('PackManager', function () {
_id: '12345', _id: '12345',
pack: [ pack: [
{ op: 'op-1', meta: 'meta-1', v: 1 }, { op: 'op-1', meta: 'meta-1', v: 1 },
{ op: 'op-2', meta: 'meta-2', v: 2 } { op: 'op-2', meta: 'meta-2', v: 2 },
], ],
n: 2, n: 2,
sz: 100, sz: 100,
meta: { start_ts: Date.now() - 6 * 3600 * 1000 }, meta: { start_ts: Date.now() - 6 * 3600 * 1000 },
expiresAt: new Date(Date.now()) expiresAt: new Date(Date.now()),
} }
return this.PackManager.flushCompressedUpdates( return this.PackManager.flushCompressedUpdates(
@ -499,7 +499,7 @@ describe('PackManager', function () {
doc_id: ObjectId(this.doc_id), doc_id: ObjectId(this.doc_id),
n: this.newUpdates.length, n: this.newUpdates.length,
v: this.newUpdates[0].v, v: this.newUpdates[0].v,
v_end: this.newUpdates[this.newUpdates.length - 1].v v_end: this.newUpdates[this.newUpdates.length - 1].v,
}) })
.should.equal(true) .should.equal(true)
}) })
@ -522,12 +522,12 @@ describe('PackManager', function () {
_id: '12345', _id: '12345',
pack: [ pack: [
{ op: 'op-1', meta: 'meta-1', v: 1 }, { op: 'op-1', meta: 'meta-1', v: 1 },
{ op: 'op-2', meta: 'meta-2', v: 2 } { op: 'op-2', meta: 'meta-2', v: 2 },
], ],
n: 2, n: 2,
sz: 100, sz: 100,
meta: { start_ts: Date.now() - 30 * 24 * 3600 * 1000 }, meta: { start_ts: Date.now() - 30 * 24 * 3600 * 1000 },
expiresAt: new Date(Date.now() - 30 * 24 * 3600 * 1000) expiresAt: new Date(Date.now() - 30 * 24 * 3600 * 1000),
} }
return this.PackManager.flushCompressedUpdates( return this.PackManager.flushCompressedUpdates(
@ -549,7 +549,7 @@ describe('PackManager', function () {
doc_id: ObjectId(this.doc_id), doc_id: ObjectId(this.doc_id),
n: this.newUpdates.length, n: this.newUpdates.length,
v: this.newUpdates[0].v, v: this.newUpdates[0].v,
v_end: this.newUpdates[this.newUpdates.length - 1].v v_end: this.newUpdates[this.newUpdates.length - 1].v,
}) })
.should.equal(true) .should.equal(true)
}) })
@ -557,7 +557,7 @@ describe('PackManager', function () {
it('should set an expiry time in the future', function () { it('should set an expiry time in the future', function () {
return this.db.docHistory.insertOne return this.db.docHistory.insertOne
.calledWithMatch({ .calledWithMatch({
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000) expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000),
}) })
.should.equal(true) .should.equal(true)
}) })
@ -602,7 +602,7 @@ describe('PackManager', function () {
describe('when an archive is in progress', function () { describe('when an archive is in progress', function () {
beforeEach(function () { beforeEach(function () {
this.db.docHistoryIndex = { this.db.docHistoryIndex = {
findOne: sinon.stub().callsArgWith(2, null, { inS3: false }) findOne: sinon.stub().callsArgWith(2, null, { inS3: false }),
} }
return this.PackManager.checkArchiveNotInProgress( return this.PackManager.checkArchiveNotInProgress(
this.project_id, this.project_id,
@ -624,7 +624,7 @@ describe('PackManager', function () {
describe('when an archive is completed', function () { describe('when an archive is completed', function () {
beforeEach(function () { beforeEach(function () {
this.db.docHistoryIndex = { this.db.docHistoryIndex = {
findOne: sinon.stub().callsArgWith(2, null, { inS3: true }) findOne: sinon.stub().callsArgWith(2, null, { inS3: true }),
} }
return this.PackManager.checkArchiveNotInProgress( return this.PackManager.checkArchiveNotInProgress(
this.project_id, this.project_id,
@ -646,7 +646,7 @@ describe('PackManager', function () {
return describe('when the archive has not started or completed', function () { return describe('when the archive has not started or completed', function () {
beforeEach(function () { beforeEach(function () {
this.db.docHistoryIndex = { this.db.docHistoryIndex = {
findOne: sinon.stub().callsArgWith(2, null, {}) findOne: sinon.stub().callsArgWith(2, null, {}),
} }
return this.PackManager.checkArchiveNotInProgress( return this.PackManager.checkArchiveNotInProgress(
this.project_id, this.project_id,

View file

@ -24,9 +24,9 @@ describe('RedisManager', function () {
createClient: () => { createClient: () => {
return (this.rclient = { return (this.rclient = {
auth: sinon.stub(), auth: sinon.stub(),
multi: () => this.rclient multi: () => this.rclient,
}) })
} },
}, },
'@overleaf/settings': { '@overleaf/settings': {
redis: { redis: {
@ -37,12 +37,12 @@ describe('RedisManager', function () {
}, },
docsWithHistoryOps({ project_id }) { docsWithHistoryOps({ project_id }) {
return `DocsWithHistoryOps:${project_id}` return `DocsWithHistoryOps:${project_id}`
} },
} },
} },
} },
} },
} },
}) })
this.doc_id = 'doc-id-123' this.doc_id = 'doc-id-123'
this.project_id = 'project-id-123' this.project_id = 'project-id-123'
@ -54,9 +54,9 @@ describe('RedisManager', function () {
beforeEach(function () { beforeEach(function () {
this.rawUpdates = [ this.rawUpdates = [
{ v: 42, op: 'mock-op-42' }, { v: 42, op: 'mock-op-42' },
{ v: 45, op: 'mock-op-45' } { v: 45, op: 'mock-op-45' },
] ]
this.jsonUpdates = Array.from(this.rawUpdates).map((update) => this.jsonUpdates = Array.from(this.rawUpdates).map(update =>
JSON.stringify(update) JSON.stringify(update)
) )
this.rclient.lrange = sinon.stub().callsArgWith(3, null, this.jsonUpdates) this.rclient.lrange = sinon.stub().callsArgWith(3, null, this.jsonUpdates)

View file

@ -19,8 +19,8 @@ describe('RestoreManager', function () {
this.RestoreManager = SandboxedModule.require(modulePath, { this.RestoreManager = SandboxedModule.require(modulePath, {
requires: { requires: {
'./DocumentUpdaterManager': (this.DocumentUpdaterManager = {}), './DocumentUpdaterManager': (this.DocumentUpdaterManager = {}),
'./DiffManager': (this.DiffManager = {}) './DiffManager': (this.DiffManager = {}),
} },
}) })
this.callback = sinon.stub() this.callback = sinon.stub()
this.project_id = 'mock-project-id' this.project_id = 'mock-project-id'

View file

@ -15,18 +15,18 @@ const modulePath = '../../../../app/js/UpdateCompressor.js'
const SandboxedModule = require('sandboxed-module') const SandboxedModule = require('sandboxed-module')
const bigstring = __range__(0, 2 * 1024 * 1024, true) const bigstring = __range__(0, 2 * 1024 * 1024, true)
.map((i) => 'a') .map(i => 'a')
.join('') .join('')
const mediumstring = __range__(0, 1024 * 1024, true) const mediumstring = __range__(0, 1024 * 1024, true)
.map((j) => 'a') .map(j => 'a')
.join('') .join('')
describe('UpdateCompressor', function () { describe('UpdateCompressor', function () {
beforeEach(function () { beforeEach(function () {
this.UpdateCompressor = SandboxedModule.require(modulePath, { this.UpdateCompressor = SandboxedModule.require(modulePath, {
requires: { requires: {
'../lib/diff_match_patch': require('../../../../app/lib/diff_match_patch') '../lib/diff_match_patch': require('../../../../app/lib/diff_match_patch'),
} },
}) })
this.user_id = 'user-id-1' this.user_id = 'user-id-1'
this.other_user_id = 'user-id-2' this.other_user_id = 'user-id-2'
@ -41,37 +41,37 @@ describe('UpdateCompressor', function () {
{ {
op: [ op: [
(this.op1 = { p: 0, i: 'Foo' }), (this.op1 = { p: 0, i: 'Foo' }),
(this.op2 = { p: 6, i: 'bar' }) (this.op2 = { p: 6, i: 'bar' }),
], ],
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: [(this.op3 = { p: 10, i: 'baz' })], op: [(this.op3 = { p: 10, i: 'baz' })],
meta: { ts: this.ts2, user_id: this.other_user_id }, meta: { ts: this.ts2, user_id: this.other_user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
op: this.op1, op: this.op1,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id }, meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: this.op2, op: this.op2,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id }, meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: this.op3, op: this.op3,
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.other_user_id user_id: this.other_user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -81,15 +81,15 @@ describe('UpdateCompressor', function () {
{ {
op: [], op: [],
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
op: this.UpdateCompressor.NOOP, op: this.UpdateCompressor.NOOP,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id }, meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
} },
]) ])
}) })
@ -100,23 +100,23 @@ describe('UpdateCompressor', function () {
op: [ op: [
(this.op1 = { p: 0, i: 'Foo' }), (this.op1 = { p: 0, i: 'Foo' }),
(this.op2 = { p: 9, c: 'baz' }), (this.op2 = { p: 9, c: 'baz' }),
(this.op3 = { p: 6, i: 'bar' }) (this.op3 = { p: 6, i: 'bar' }),
], ],
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
op: this.op1, op: this.op1,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id }, meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: this.op3, op: this.op3,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id }, meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
} },
]) ])
}) })
}) })
@ -130,44 +130,44 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: (this.op2 = { p: 6, i: 'bar' }), op: (this.op2 = { p: 6, i: 'bar' }),
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: (this.op3 = { p: 10, i: 'baz' }), op: (this.op3 = { p: 10, i: 'baz' }),
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.other_user_id user_id: this.other_user_id,
},
v: 43,
}, },
v: 43
}
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
op: [this.op1, this.op2], op: [this.op1, this.op2],
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id }, meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: [this.op3], op: [this.op3],
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.other_user_id user_id: this.other_user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -179,17 +179,17 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
},
v: 42,
}, },
v: 42
}
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
op: [], op: [],
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id }, meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
} },
]) ])
}) })
}) })
@ -202,13 +202,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'foo' }, op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 6, i: 'bar' }, op: { p: 6, i: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -216,10 +216,10 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -229,13 +229,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'foo' }, op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 5, i: 'bar' }, op: { p: 5, i: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -243,10 +243,10 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -256,13 +256,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'foo' }, op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 9, i: 'bar' }, op: { p: 9, i: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -270,19 +270,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 9, i: 'bar' }, op: { p: 9, i: 'bar' },
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -292,13 +292,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'foo' }, op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 6, i: bigstring }, op: { p: 6, i: bigstring },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -306,19 +306,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 6, i: bigstring }, op: { p: 6, i: bigstring },
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -328,13 +328,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: bigstring }, op: { p: 3, i: bigstring },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 3 + bigstring.length, i: 'bar' }, op: { p: 3 + bigstring.length, i: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -342,19 +342,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 3 + bigstring.length, i: 'bar' }, op: { p: 3 + bigstring.length, i: 'bar' },
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -364,13 +364,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: mediumstring }, op: { p: 3, i: mediumstring },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 3 + mediumstring.length, i: mediumstring }, op: { p: 3 + mediumstring.length, i: mediumstring },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -378,19 +378,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 3 + mediumstring.length, i: mediumstring }, op: { p: 3 + mediumstring.length, i: mediumstring },
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
}) })
@ -402,13 +402,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, d: 'foo' }, op: { p: 3, d: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 3, d: 'bar' }, op: { p: 3, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -416,10 +416,10 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -429,13 +429,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, d: 'foo' }, op: { p: 3, d: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 1, d: 'bar' }, op: { p: 1, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -443,10 +443,10 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -456,13 +456,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, d: 'foo' }, op: { p: 3, d: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 9, d: 'bar' }, op: { p: 9, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -470,19 +470,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 9, d: 'bar' }, op: { p: 9, d: 'bar' },
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
}) })
@ -494,13 +494,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'foo' }, op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 5, d: 'o' }, op: { p: 5, d: 'o' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -508,10 +508,10 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -521,13 +521,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'fobaro' }, op: { p: 3, i: 'fobaro' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 5, d: 'bar' }, op: { p: 5, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -535,10 +535,10 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -548,13 +548,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'foo' }, op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 3, d: 'foo' }, op: { p: 3, d: 'foo' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -562,10 +562,10 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -575,13 +575,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'foo' }, op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 9, d: 'bar' }, op: { p: 9, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -589,19 +589,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 9, d: 'bar' }, op: { p: 9, d: 'bar' },
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -611,13 +611,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, i: 'foobar' }, op: { p: 3, i: 'foobar' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 6, d: 'bardle' }, op: { p: 6, d: 'bardle' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -625,19 +625,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 6, d: 'bardle' }, op: { p: 6, d: 'bardle' },
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
}) })
@ -649,13 +649,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, d: 'one two three four five six seven eight' }, op: { p: 3, d: 'one two three four five six seven eight' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 3, i: 'one 2 three four five six seven eight' }, op: { p: 3, i: 'one 2 three four five six seven eight' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -663,19 +663,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
}, },
v: 43 v: 43,
}, },
{ {
op: { p: 7, i: '2' }, op: { p: 7, i: '2' },
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
@ -685,13 +685,13 @@ describe('UpdateCompressor', function () {
{ {
op: { p: 3, d: 'one two three four five six seven eight' }, op: { p: 3, d: 'one two three four five six seven eight' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 3, i: 'one two three four five six seven eight' }, op: { p: 3, i: 'one two three four five six seven eight' },
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -699,10 +699,10 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
}) })
@ -714,13 +714,13 @@ describe('UpdateCompressor', function () {
{ {
op: this.UpdateCompressor.NOOP, op: this.UpdateCompressor.NOOP,
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 6, i: 'bar' }, op: { p: 6, i: 'bar' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -728,19 +728,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 6, i: 'bar' }, op: { p: 6, i: 'bar' },
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
}) })
@ -752,13 +752,13 @@ describe('UpdateCompressor', function () {
{ {
op: this.UpdateCompressor.NOOP, op: this.UpdateCompressor.NOOP,
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 42 v: 42,
}, },
{ {
op: { p: 6, d: 'bar' }, op: { p: 6, d: 'bar' },
meta: { ts: this.ts1, user_id: this.user_id }, meta: { ts: this.ts1, user_id: this.user_id },
v: 43 v: 43,
} },
]) ])
).to.deep.equal([ ).to.deep.equal([
{ {
@ -766,19 +766,19 @@ describe('UpdateCompressor', function () {
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: { p: 6, d: 'bar' }, op: { p: 6, d: 'bar' },
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
}) })
@ -792,45 +792,45 @@ describe('UpdateCompressor', function () {
{ {
op: [ op: [
{ p: 1000, d: 'hello' }, { p: 1000, d: 'hello' },
{ p: 1000, i: 'HELLO()' } { p: 1000, i: 'HELLO()' },
], ],
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
[ [
{ {
op: [{ p: 1006, i: 'WORLD' }], op: [{ p: 1006, i: 'WORLD' }],
meta: { ts: this.ts2, user_id: this.user_id }, meta: { ts: this.ts2, user_id: this.user_id },
v: 43 v: 43,
} },
] ]
) )
).to.deep.equal([ ).to.deep.equal([
{ {
op: [ op: [
{ p: 1000, d: 'hello' }, { p: 1000, d: 'hello' },
{ p: 1000, i: 'HELLO()' } { p: 1000, i: 'HELLO()' },
], ],
meta: { meta: {
start_ts: this.ts1, start_ts: this.ts1,
end_ts: this.ts1, end_ts: this.ts1,
user_id: this.user_id user_id: this.user_id,
}, },
v: 42 v: 42,
}, },
{ {
op: [{ p: 1006, i: 'WORLD' }], op: [{ p: 1006, i: 'WORLD' }],
meta: { meta: {
start_ts: this.ts2, start_ts: this.ts2,
end_ts: this.ts2, end_ts: this.ts2,
user_id: this.user_id user_id: this.user_id,
},
v: 43,
}, },
v: 43
}
]) ])
}) })
}) })

View file

@ -23,8 +23,8 @@ describe('UpdateTrimmer', function () {
this.UpdateTrimmer = SandboxedModule.require(modulePath, { this.UpdateTrimmer = SandboxedModule.require(modulePath, {
requires: { requires: {
'./WebApiManager': (this.WebApiManager = {}), './WebApiManager': (this.WebApiManager = {}),
'./MongoManager': (this.MongoManager = {}) './MongoManager': (this.MongoManager = {}),
} },
}) })
this.callback = sinon.stub() this.callback = sinon.stub()

View file

@ -38,12 +38,12 @@ describe('UpdatesManager', function () {
key_schema: { key_schema: {
historyLock({ doc_id }) { historyLock({ doc_id }) {
return `HistoryLock:${doc_id}` return `HistoryLock:${doc_id}`
} },
} },
} },
} },
} },
} },
}) })
this.doc_id = 'doc-id-123' this.doc_id = 'doc-id-123'
this.project_id = 'project-id-123' this.project_id = 'project-id-123'
@ -79,7 +79,7 @@ describe('UpdatesManager', function () {
beforeEach(function () { beforeEach(function () {
this.rawUpdates = [ this.rawUpdates = [
{ v: 12, op: 'mock-op-12' }, { v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' } { v: 13, op: 'mock-op-13' },
] ]
this.compressedUpdates = [{ v: 13, op: 'compressed-op-12' }] this.compressedUpdates = [{ v: 13, op: 'compressed-op-12' }]
@ -127,7 +127,7 @@ describe('UpdatesManager', function () {
this.lastCompressedUpdate = { v: 11, op: 'compressed-op-11' } this.lastCompressedUpdate = { v: 11, op: 'compressed-op-11' }
this.compressedUpdates = [ this.compressedUpdates = [
{ v: 12, op: 'compressed-op-11+12' }, { v: 12, op: 'compressed-op-11+12' },
{ v: 13, op: 'compressed-op-12' } { v: 13, op: 'compressed-op-12' },
] ]
this.MongoManager.peekLastCompressedUpdate = sinon this.MongoManager.peekLastCompressedUpdate = sinon
@ -148,7 +148,7 @@ describe('UpdatesManager', function () {
beforeEach(function () { beforeEach(function () {
this.rawUpdates = [ this.rawUpdates = [
{ v: 12, op: 'mock-op-12' }, { v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' } { v: 13, op: 'mock-op-13' },
] ]
return this.UpdatesManager.compressAndSaveRawUpdates( return this.UpdatesManager.compressAndSaveRawUpdates(
this.project_id, this.project_id,
@ -192,11 +192,11 @@ describe('UpdatesManager', function () {
beforeEach(function () { beforeEach(function () {
this.lastCompressedUpdate = { this.lastCompressedUpdate = {
pack: [{ v: 11, op: 'compressed-op-11' }], pack: [{ v: 11, op: 'compressed-op-11' }],
v: 11 v: 11,
} }
this.rawUpdates = [ this.rawUpdates = [
{ v: 12, op: 'mock-op-12' }, { v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' } { v: 13, op: 'mock-op-13' },
] ]
this.MongoManager.peekLastCompressedUpdate = sinon this.MongoManager.peekLastCompressedUpdate = sinon
.stub() .stub()
@ -250,7 +250,7 @@ describe('UpdatesManager', function () {
{ v: 10, op: 'mock-op-10' }, { v: 10, op: 'mock-op-10' },
{ v: 11, op: 'mock-op-11' }, { v: 11, op: 'mock-op-11' },
{ v: 12, op: 'mock-op-12' }, { v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' } { v: 13, op: 'mock-op-13' },
] ]
return this.UpdatesManager.compressAndSaveRawUpdates( return this.UpdatesManager.compressAndSaveRawUpdates(
@ -303,7 +303,7 @@ describe('UpdatesManager', function () {
beforeEach(function () { beforeEach(function () {
this.rawUpdates = [ this.rawUpdates = [
{ v: 13, op: 'mock-op-13' }, { v: 13, op: 'mock-op-13' },
{ v: 12, op: 'mock-op-12' } { v: 12, op: 'mock-op-12' },
] ]
return this.UpdatesManager.compressAndSaveRawUpdates( return this.UpdatesManager.compressAndSaveRawUpdates(
this.project_id, this.project_id,
@ -347,7 +347,7 @@ describe('UpdatesManager', function () {
beforeEach(function () { beforeEach(function () {
this.rawUpdates = [ this.rawUpdates = [
{ v: 12, op: 'mock-op-12' }, { v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' } { v: 13, op: 'mock-op-13' },
] ]
return this.UpdatesManager.compressAndSaveRawUpdates( return this.UpdatesManager.compressAndSaveRawUpdates(
this.project_id, this.project_id,
@ -454,7 +454,7 @@ describe('UpdatesManager', function () {
'mock-update-1', 'mock-update-1',
'mock-update-2', 'mock-update-2',
'mock-update-3', 'mock-update-3',
'mock-update-4' 'mock-update-4',
] ]
this.redisArray = this.updates.slice() this.redisArray = this.updates.slice()
this.RedisManager.getOldestDocUpdates = ( this.RedisManager.getOldestDocUpdates = (
@ -673,7 +673,7 @@ describe('UpdatesManager', function () {
}) })
it('should process the doc ops for the each doc_id', function () { it('should process the doc ops for the each doc_id', function () {
return Array.from(this.doc_ids).map((doc_id) => return Array.from(this.doc_ids).map(doc_id =>
this.UpdatesManager._processUncompressedUpdatesForDocWithLock this.UpdatesManager._processUncompressedUpdatesForDocWithLock
.calledWith(this.project_id, doc_id, this.temporary) .calledWith(this.project_id, doc_id, this.temporary)
.should.equal(true) .should.equal(true)
@ -692,26 +692,26 @@ describe('UpdatesManager', function () {
doc_id: 123, doc_id: 123,
v: 456, v: 456,
op: 'mock-updates', op: 'mock-updates',
meta: { user_id: 123, start_ts: 1233, end_ts: 1234 } meta: { user_id: 123, start_ts: 1233, end_ts: 1234 },
} },
] ]
this.options = { before: 'mock-before', limit: 'mock-limit' } this.options = { before: 'mock-before', limit: 'mock-limit' }
this.summarizedUpdates = [ this.summarizedUpdates = [
{ {
meta: { user_ids: [123], start_ts: 1233, end_ts: 1234 }, meta: { user_ids: [123], start_ts: 1233, end_ts: 1234 },
docs: { '123': { fromV: 456, toV: 456 } } docs: { 123: { fromV: 456, toV: 456 } },
} },
] ]
this.updatesWithUserInfo = ['updates-with-user-info'] this.updatesWithUserInfo = ['updates-with-user-info']
this.done_state = false this.done_state = false
this.iterator = { this.iterator = {
next: (cb) => { next: cb => {
this.done_state = true this.done_state = true
return cb(null, this.updates) return cb(null, this.updates)
}, },
done: () => { done: () => {
return this.done_state return this.done_state
} },
} }
this.PackManager.makeProjectIterator = sinon this.PackManager.makeProjectIterator = sinon
.stub() .stub()
@ -867,22 +867,22 @@ describe('UpdatesManager', function () {
this.updates = [ this.updates = [
{ {
meta: { meta: {
user_id: this.user_id_1 user_id: this.user_id_1,
}, },
op: 'mock-op-1' op: 'mock-op-1',
}, },
{ {
meta: { meta: {
user_id: this.user_id_1 user_id: this.user_id_1,
}, },
op: 'mock-op-2' op: 'mock-op-2',
}, },
{ {
meta: { meta: {
user_id: this.user_id_2 user_id: this.user_id_2,
},
op: 'mock-op-3',
}, },
op: 'mock-op-3'
}
] ]
this.user_info = {} this.user_info = {}
this.user_info[this.user_id_1] = { email: 'user1@sharelatex.com' } this.user_info[this.user_id_1] = { email: 'user1@sharelatex.com' }
@ -920,27 +920,27 @@ describe('UpdatesManager', function () {
{ {
meta: { meta: {
user: { user: {
email: 'user1@sharelatex.com' email: 'user1@sharelatex.com',
}
}, },
op: 'mock-op-1' },
op: 'mock-op-1',
}, },
{ {
meta: { meta: {
user: { user: {
email: 'user1@sharelatex.com' email: 'user1@sharelatex.com',
}
}, },
op: 'mock-op-2' },
op: 'mock-op-2',
}, },
{ {
meta: { meta: {
user: { user: {
email: 'user2@sharelatex.com' email: 'user2@sharelatex.com',
} },
},
op: 'mock-op-3',
}, },
op: 'mock-op-3'
}
]) ])
}) })
}) })
@ -950,16 +950,16 @@ describe('UpdatesManager', function () {
this.updates = [ this.updates = [
{ {
meta: { meta: {
user_id: null user_id: null,
}, },
op: 'mock-op-1' op: 'mock-op-1',
}, },
{ {
meta: { meta: {
user_id: 'anonymous-user' user_id: 'anonymous-user',
},
op: 'mock-op-2',
}, },
op: 'mock-op-2'
}
] ]
this.WebApiManager.getUserInfo = (user_id, callback) => { this.WebApiManager.getUserInfo = (user_id, callback) => {
if (callback == null) { if (callback == null) {
@ -986,12 +986,12 @@ describe('UpdatesManager', function () {
return expect(this.results).to.deep.equal([ return expect(this.results).to.deep.equal([
{ {
meta: {}, meta: {},
op: 'mock-op-1' op: 'mock-op-1',
}, },
{ {
meta: {}, meta: {},
op: 'mock-op-2' op: 'mock-op-2',
} },
]) ])
}) })
}) })
@ -1011,19 +1011,19 @@ describe('UpdatesManager', function () {
meta: { meta: {
user_id: this.user_1.id, user_id: this.user_1.id,
start_ts: this.now + 20, start_ts: this.now + 20,
end_ts: this.now + 30 end_ts: this.now + 30,
}, },
v: 5 v: 5,
}, },
{ {
doc_id: 'doc-id-1', doc_id: 'doc-id-1',
meta: { meta: {
user_id: this.user_2.id, user_id: this.user_2.id,
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
},
v: 4,
}, },
v: 4
}
]) ])
return expect(result).to.deep.equal([ return expect(result).to.deep.equal([
@ -1031,15 +1031,15 @@ describe('UpdatesManager', function () {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 4, fromV: 4,
toV: 5 toV: 5,
} },
}, },
meta: { meta: {
user_ids: [this.user_1.id, this.user_2.id], user_ids: [this.user_1.id, this.user_2.id],
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 30 end_ts: this.now + 30,
} },
} },
]) ])
}) })
@ -1051,47 +1051,47 @@ describe('UpdatesManager', function () {
meta: { meta: {
user_id: this.user_2.id, user_id: this.user_2.id,
start_ts: this.now + oneDay, start_ts: this.now + oneDay,
end_ts: this.now + oneDay + 10 end_ts: this.now + oneDay + 10,
}, },
v: 5 v: 5,
}, },
{ {
doc_id: 'doc-id-1', doc_id: 'doc-id-1',
meta: { meta: {
user_id: this.user_1.id, user_id: this.user_1.id,
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
},
v: 4,
}, },
v: 4
}
]) ])
return expect(result).to.deep.equal([ return expect(result).to.deep.equal([
{ {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 5, fromV: 5,
toV: 5 toV: 5,
} },
}, },
meta: { meta: {
user_ids: [this.user_2.id], user_ids: [this.user_2.id],
start_ts: this.now + oneDay, start_ts: this.now + oneDay,
end_ts: this.now + oneDay + 10 end_ts: this.now + oneDay + 10,
} },
}, },
{ {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 4, fromV: 4,
toV: 4 toV: 4,
} },
}, },
meta: { meta: {
user_ids: [this.user_1.id], user_ids: [this.user_1.id],
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
} },
} },
]) ])
}) })
@ -1103,34 +1103,34 @@ describe('UpdatesManager', function () {
meta: { meta: {
user_id: this.user_1.id, user_id: this.user_1.id,
start_ts: this.now + 20, start_ts: this.now + 20,
end_ts: this.now + 30 end_ts: this.now + 30,
}, },
v: 5 v: 5,
}, },
{ {
doc_id: 'doc-id-2', doc_id: 'doc-id-2',
meta: { meta: {
user_id: this.user_2.id, user_id: this.user_2.id,
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
},
v: 4,
}, },
v: 4
}
], ],
[ [
{ {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 6, fromV: 6,
toV: 8 toV: 8,
} },
}, },
meta: { meta: {
user_ids: [this.user_1.id], user_ids: [this.user_1.id],
start_ts: this.now + 40, start_ts: this.now + 40,
end_ts: this.now + 50 end_ts: this.now + 50,
} },
} },
] ]
) )
return expect(result).to.deep.equal([ return expect(result).to.deep.equal([
@ -1138,19 +1138,19 @@ describe('UpdatesManager', function () {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
toV: 8, toV: 8,
fromV: 6 fromV: 6,
}, },
'doc-id-2': { 'doc-id-2': {
toV: 5, toV: 5,
fromV: 4 fromV: 4,
} },
}, },
meta: { meta: {
user_ids: [this.user_1.id, this.user_2.id], user_ids: [this.user_1.id, this.user_2.id],
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 50 end_ts: this.now + 50,
} },
} },
]) ])
}) })
@ -1161,34 +1161,34 @@ describe('UpdatesManager', function () {
meta: { meta: {
user_id: this.user_1.id, user_id: this.user_1.id,
start_ts: this.now + 20, start_ts: this.now + 20,
end_ts: this.now + 30 end_ts: this.now + 30,
}, },
v: 5 v: 5,
}, },
{ {
doc_id: 'doc-id-1', doc_id: 'doc-id-1',
meta: { meta: {
user_id: null, user_id: null,
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
},
v: 4,
}, },
v: 4
}
]) ])
return expect(result).to.deep.equal([ return expect(result).to.deep.equal([
{ {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 4, fromV: 4,
toV: 5 toV: 5,
} },
}, },
meta: { meta: {
user_ids: [this.user_1.id, null], user_ids: [this.user_1.id, null],
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 30 end_ts: this.now + 30,
} },
} },
]) ])
}) })
@ -1199,34 +1199,34 @@ describe('UpdatesManager', function () {
meta: { meta: {
user_id: null, user_id: null,
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
}, },
v: 4 v: 4,
}, },
{ {
doc_id: 'doc-id-1', doc_id: 'doc-id-1',
meta: { meta: {
user_id: this.user_1.id, user_id: this.user_1.id,
start_ts: this.now + 20, start_ts: this.now + 20,
end_ts: this.now + 30 end_ts: this.now + 30,
},
v: 5,
}, },
v: 5
}
]) ])
return expect(result).to.deep.equal([ return expect(result).to.deep.equal([
{ {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 4, fromV: 4,
toV: 5 toV: 5,
} },
}, },
meta: { meta: {
user_ids: [null, this.user_1.id], user_ids: [null, this.user_1.id],
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 30 end_ts: this.now + 30,
} },
} },
]) ])
}) })
@ -1237,43 +1237,43 @@ describe('UpdatesManager', function () {
meta: { meta: {
user_id: this.user_1.id, user_id: this.user_1.id,
start_ts: this.now + 20, start_ts: this.now + 20,
end_ts: this.now + 30 end_ts: this.now + 30,
}, },
v: 5 v: 5,
}, },
{ {
doc_id: 'doc-id-1', doc_id: 'doc-id-1',
meta: { meta: {
user_id: null, user_id: null,
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
}, },
v: 4 v: 4,
}, },
{ {
doc_id: 'doc-id-1', doc_id: 'doc-id-1',
meta: { meta: {
user_id: null, user_id: null,
start_ts: this.now + 2, start_ts: this.now + 2,
end_ts: this.now + 4 end_ts: this.now + 4,
},
v: 4,
}, },
v: 4
}
]) ])
return expect(result).to.deep.equal([ return expect(result).to.deep.equal([
{ {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 4, fromV: 4,
toV: 5 toV: 5,
} },
}, },
meta: { meta: {
user_ids: [this.user_1.id, null], user_ids: [this.user_1.id, null],
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 30 end_ts: this.now + 30,
} },
} },
]) ])
}) })
@ -1285,19 +1285,19 @@ describe('UpdatesManager', function () {
meta: { meta: {
user_id: this.user_1.id, user_id: this.user_1.id,
start_ts: this.now + 20, start_ts: this.now + 20,
end_ts: this.now + 30 end_ts: this.now + 30,
}, },
v: 5 v: 5,
}, },
{ {
doc_id: 'doc-id-1', doc_id: 'doc-id-1',
meta: { meta: {
user_id: this.user_2.id, user_id: this.user_2.id,
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
},
v: 4,
}, },
v: 4
}
]) ])
return expect(result).to.deep.equal([ return expect(result).to.deep.equal([
@ -1305,28 +1305,28 @@ describe('UpdatesManager', function () {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 5, fromV: 5,
toV: 5 toV: 5,
} },
}, },
meta: { meta: {
user_ids: [this.user_1.id], user_ids: [this.user_1.id],
start_ts: this.now + 20, start_ts: this.now + 20,
end_ts: this.now + 30 end_ts: this.now + 30,
} },
}, },
{ {
docs: { docs: {
'doc-id-1': { 'doc-id-1': {
fromV: 4, fromV: 4,
toV: 4 toV: 4,
} },
}, },
meta: { meta: {
user_ids: [this.user_2.id], user_ids: [this.user_2.id],
start_ts: this.now, start_ts: this.now,
end_ts: this.now + 10 end_ts: this.now + 10,
} },
} },
]) ])
}) })
}) })

View file

@ -24,11 +24,11 @@ describe('WebApiManager', function () {
web: { web: {
url: 'http://example.com', url: 'http://example.com',
user: 'sharelatex', user: 'sharelatex',
pass: 'password' pass: 'password',
} },
} },
}) }),
} },
}) })
this.callback = sinon.stub() this.callback = sinon.stub()
this.user_id = 'mock-user-id' this.user_id = 'mock-user-id'
@ -38,7 +38,7 @@ describe('WebApiManager', function () {
id: this.user_id, id: this.user_id,
first_name: 'Leo', first_name: 'Leo',
last_nane: 'Lion', last_nane: 'Lion',
extra_param: 'blah' extra_param: 'blah',
} }
return (this.project = { features: 'mock-features' }) return (this.project = { features: 'mock-features' })
}) })
@ -60,8 +60,8 @@ describe('WebApiManager', function () {
auth: { auth: {
user: this.settings.apis.web.user, user: this.settings.apis.web.user,
pass: this.settings.apis.web.pass, pass: this.settings.apis.web.pass,
sendImmediately: true sendImmediately: true,
} },
}) })
.should.equal(true) .should.equal(true)
}) })
@ -72,7 +72,7 @@ describe('WebApiManager', function () {
id: this.user_id, id: this.user_id,
email: this.user_info.email, email: this.user_info.email,
first_name: this.user_info.first_name, first_name: this.user_info.first_name,
last_name: this.user_info.last_name last_name: this.user_info.last_name,
}) })
.should.equal(true) .should.equal(true)
}) })
@ -150,8 +150,8 @@ describe('WebApiManager', function () {
auth: { auth: {
user: this.settings.apis.web.user, user: this.settings.apis.web.user,
pass: this.settings.apis.web.pass, pass: this.settings.apis.web.pass,
sendImmediately: true sendImmediately: true,
} },
}) })
.should.equal(true) .should.equal(true)
}) })