2024-04-02 09:49:42 -04:00
|
|
|
const { callbackifyAll } = require('@overleaf/promise-utils')
|
2020-05-06 06:09:33 -04:00
|
|
|
const RedisManager = require('./RedisManager')
|
|
|
|
const ProjectHistoryRedisManager = require('./ProjectHistoryRedisManager')
|
|
|
|
const PersistenceManager = require('./PersistenceManager')
|
|
|
|
const DiffCodec = require('./DiffCodec')
|
2021-10-06 05:10:28 -04:00
|
|
|
const logger = require('@overleaf/logger')
|
2020-05-06 06:09:33 -04:00
|
|
|
const Metrics = require('./Metrics')
|
|
|
|
const HistoryManager = require('./HistoryManager')
|
|
|
|
const Errors = require('./Errors')
|
|
|
|
const RangesManager = require('./RangesManager')
|
2024-06-17 08:54:11 -04:00
|
|
|
const { extractOriginOrSource } = require('./Utils')
|
2020-05-06 06:09:33 -04:00
|
|
|
|
|
|
|
const MAX_UNFLUSHED_AGE = 300 * 1000 // 5 mins, document should be flushed to mongo this time after a change
|
|
|
|
|
2024-01-30 10:35:54 -05:00
|
|
|
const DocumentManager = {
|
2024-04-02 09:49:42 -04:00
|
|
|
async getDoc(projectId, docId) {
|
|
|
|
const {
|
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges,
|
2024-05-28 07:24:06 -04:00
|
|
|
resolvedCommentIds,
|
2024-04-02 09:49:42 -04:00
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
|
|
|
unflushedTime,
|
|
|
|
historyRangesSupport,
|
|
|
|
} = await RedisManager.promises.getDoc(projectId, docId)
|
|
|
|
if (lines == null || version == null) {
|
|
|
|
logger.debug(
|
|
|
|
{ projectId, docId },
|
|
|
|
'doc not in redis so getting from persistence API'
|
|
|
|
)
|
|
|
|
const {
|
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges,
|
2024-05-28 07:24:06 -04:00
|
|
|
resolvedCommentIds,
|
2024-04-02 09:49:42 -04:00
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
|
|
|
historyRangesSupport,
|
|
|
|
} = await PersistenceManager.promises.getDoc(projectId, docId)
|
|
|
|
logger.debug(
|
|
|
|
{
|
|
|
|
projectId,
|
|
|
|
docId,
|
|
|
|
lines,
|
2024-05-28 07:24:06 -04:00
|
|
|
ranges,
|
|
|
|
resolvedCommentIds,
|
2024-04-02 09:49:42 -04:00
|
|
|
version,
|
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
|
|
|
historyRangesSupport,
|
|
|
|
},
|
|
|
|
'got doc from persistence API'
|
|
|
|
)
|
|
|
|
await RedisManager.promises.putDocInMemory(
|
|
|
|
projectId,
|
|
|
|
docId,
|
2021-07-13 07:04:42 -04:00
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges,
|
2024-05-28 07:24:06 -04:00
|
|
|
resolvedCommentIds,
|
2021-07-13 07:04:42 -04:00
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
2024-02-09 09:09:40 -05:00
|
|
|
historyRangesSupport
|
2024-04-02 09:49:42 -04:00
|
|
|
)
|
|
|
|
return {
|
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges: ranges || {},
|
2024-05-28 07:24:06 -04:00
|
|
|
resolvedCommentIds,
|
2024-04-02 09:49:42 -04:00
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
|
|
|
unflushedTime: null,
|
|
|
|
alreadyLoaded: false,
|
|
|
|
historyRangesSupport,
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|
2024-04-02 09:49:42 -04:00
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
lines,
|
2021-07-13 07:04:42 -04:00
|
|
|
version,
|
|
|
|
ranges,
|
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
2024-05-28 07:24:06 -04:00
|
|
|
resolvedCommentIds,
|
2021-07-13 07:04:42 -04:00
|
|
|
unflushedTime,
|
2024-04-02 09:49:42 -04:00
|
|
|
alreadyLoaded: true,
|
|
|
|
historyRangesSupport,
|
2021-07-13 07:04:42 -04:00
|
|
|
}
|
2024-04-02 09:49:42 -04:00
|
|
|
}
|
2020-05-06 06:09:33 -04:00
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async getDocAndRecentOps(projectId, docId, fromVersion) {
|
|
|
|
const { lines, version, ranges, pathname, projectHistoryId } =
|
|
|
|
await DocumentManager.getDoc(projectId, docId)
|
|
|
|
|
|
|
|
if (fromVersion === -1) {
|
|
|
|
return { lines, version, ops: [], ranges, pathname, projectHistoryId }
|
|
|
|
} else {
|
|
|
|
const ops = await RedisManager.promises.getPreviousDocOps(
|
|
|
|
docId,
|
|
|
|
fromVersion,
|
|
|
|
version
|
|
|
|
)
|
|
|
|
return {
|
2021-07-13 07:04:42 -04:00
|
|
|
lines,
|
|
|
|
version,
|
2024-04-02 09:49:42 -04:00
|
|
|
ops,
|
2021-07-13 07:04:42 -04:00
|
|
|
ranges,
|
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|
2024-04-02 09:49:42 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2024-06-17 08:54:11 -04:00
|
|
|
async setDoc(projectId, docId, newLines, originOrSource, userId, undoing) {
|
2024-04-02 09:49:42 -04:00
|
|
|
if (newLines == null) {
|
|
|
|
throw new Error('No lines were provided to setDoc')
|
|
|
|
}
|
|
|
|
|
|
|
|
const UpdateManager = require('./UpdateManager')
|
|
|
|
const {
|
|
|
|
lines: oldLines,
|
|
|
|
version,
|
|
|
|
alreadyLoaded,
|
|
|
|
} = await DocumentManager.getDoc(projectId, docId)
|
|
|
|
|
|
|
|
if (oldLines != null && oldLines.length > 0 && oldLines[0].text != null) {
|
|
|
|
logger.debug(
|
|
|
|
{ docId, projectId, oldLines, newLines },
|
|
|
|
'document is JSON so not updating'
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.debug(
|
|
|
|
{ docId, projectId, oldLines, newLines },
|
|
|
|
'setting a document via http'
|
2021-07-13 07:04:42 -04:00
|
|
|
)
|
2024-04-02 09:49:42 -04:00
|
|
|
const op = DiffCodec.diffAsShareJsOp(oldLines, newLines)
|
|
|
|
if (undoing) {
|
|
|
|
for (const o of op || []) {
|
|
|
|
o.u = true
|
|
|
|
} // Turn on undo flag for each op for track changes
|
|
|
|
}
|
2024-06-17 08:54:11 -04:00
|
|
|
|
|
|
|
const { origin, source } = extractOriginOrSource(originOrSource)
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
const update = {
|
|
|
|
doc: docId,
|
|
|
|
op,
|
|
|
|
v: version,
|
|
|
|
meta: {
|
|
|
|
type: 'external',
|
|
|
|
user_id: userId,
|
|
|
|
},
|
|
|
|
}
|
2024-06-17 08:54:11 -04:00
|
|
|
if (origin) {
|
|
|
|
update.meta.origin = origin
|
|
|
|
} else if (source) {
|
|
|
|
update.meta.source = source
|
|
|
|
}
|
2024-04-02 09:49:42 -04:00
|
|
|
// Keep track of external updates, whether they are for live documents
|
|
|
|
// (flush) or unloaded documents (evict), and whether the update is a no-op.
|
|
|
|
Metrics.inc('external-update', 1, {
|
|
|
|
status: op.length > 0 ? 'diff' : 'noop',
|
|
|
|
method: alreadyLoaded ? 'flush' : 'evict',
|
|
|
|
path: source,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Do not notify the frontend about a noop update.
|
|
|
|
// We still want to execute the code below
|
|
|
|
// to evict the doc if we loaded it into redis for
|
|
|
|
// this update, otherwise the doc would never be
|
|
|
|
// removed from redis.
|
|
|
|
if (op.length > 0) {
|
|
|
|
await UpdateManager.promises.applyUpdate(projectId, docId, update)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the document was loaded already, then someone has it open
|
|
|
|
// in a project, and the usual flushing mechanism will happen.
|
|
|
|
// Otherwise we should remove it immediately since nothing else
|
|
|
|
// is using it.
|
|
|
|
if (alreadyLoaded) {
|
|
|
|
return await DocumentManager.flushDocIfLoaded(projectId, docId)
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
return await DocumentManager.flushAndDeleteDoc(projectId, docId, {})
|
|
|
|
} finally {
|
|
|
|
// There is no harm in flushing project history if the previous
|
|
|
|
// call failed and sometimes it is required
|
|
|
|
HistoryManager.flushProjectChangesAsync(projectId)
|
|
|
|
}
|
|
|
|
}
|
2020-05-06 06:09:33 -04:00
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async flushDocIfLoaded(projectId, docId) {
|
|
|
|
const {
|
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges,
|
|
|
|
unflushedTime,
|
|
|
|
lastUpdatedAt,
|
|
|
|
lastUpdatedBy,
|
|
|
|
} = await RedisManager.promises.getDoc(projectId, docId)
|
|
|
|
if (lines == null || version == null) {
|
|
|
|
Metrics.inc('flush-doc-if-loaded', 1, { status: 'not-loaded' })
|
|
|
|
logger.debug({ projectId, docId }, 'doc is not loaded so not flushing')
|
|
|
|
// TODO: return a flag to bail out, as we go on to remove doc from memory?
|
|
|
|
return
|
|
|
|
} else if (unflushedTime == null) {
|
|
|
|
Metrics.inc('flush-doc-if-loaded', 1, { status: 'unmodified' })
|
|
|
|
logger.debug({ projectId, docId }, 'doc is not modified so not flushing')
|
|
|
|
return
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
logger.debug({ projectId, docId, version }, 'flushing doc')
|
|
|
|
Metrics.inc('flush-doc-if-loaded', 1, { status: 'modified' })
|
|
|
|
const result = await PersistenceManager.promises.setDoc(
|
|
|
|
projectId,
|
|
|
|
docId,
|
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges,
|
|
|
|
lastUpdatedAt,
|
2024-06-17 08:54:54 -04:00
|
|
|
lastUpdatedBy || null
|
2024-04-02 09:49:42 -04:00
|
|
|
)
|
|
|
|
await RedisManager.promises.clearUnflushedTime(docId)
|
|
|
|
return result
|
|
|
|
},
|
|
|
|
|
|
|
|
async flushAndDeleteDoc(projectId, docId, options) {
|
|
|
|
let result
|
|
|
|
try {
|
|
|
|
result = await DocumentManager.flushDocIfLoaded(projectId, docId)
|
|
|
|
} catch (error) {
|
|
|
|
if (options.ignoreFlushErrors) {
|
|
|
|
logger.warn(
|
|
|
|
{ projectId, docId, err: error },
|
|
|
|
'ignoring flush error while deleting document'
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
throw error
|
2021-11-30 08:26:20 -05:00
|
|
|
}
|
2024-04-02 09:49:42 -04:00
|
|
|
}
|
2020-05-06 06:09:33 -04:00
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
await RedisManager.promises.removeDocFromMemory(projectId, docId)
|
|
|
|
return result
|
2020-05-06 06:09:33 -04:00
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async acceptChanges(projectId, docId, changeIds) {
|
2021-11-30 08:26:20 -05:00
|
|
|
if (changeIds == null) {
|
|
|
|
changeIds = []
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|
2024-04-02 09:49:42 -04:00
|
|
|
|
2024-04-16 04:55:56 -04:00
|
|
|
const {
|
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges,
|
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
|
|
|
historyRangesSupport,
|
|
|
|
} = await DocumentManager.getDoc(projectId, docId)
|
2024-04-02 09:49:42 -04:00
|
|
|
if (lines == null || version == null) {
|
|
|
|
throw new Errors.NotFoundError(`document not found: ${docId}`)
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|
|
|
|
|
2024-10-29 10:12:01 -04:00
|
|
|
const newRanges = RangesManager.acceptChanges(
|
|
|
|
projectId,
|
|
|
|
docId,
|
|
|
|
changeIds,
|
|
|
|
ranges,
|
|
|
|
lines
|
|
|
|
)
|
2024-04-02 09:49:42 -04:00
|
|
|
|
|
|
|
await RedisManager.promises.updateDocument(
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
2024-04-02 09:49:42 -04:00
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
[],
|
|
|
|
newRanges,
|
|
|
|
{}
|
2021-07-13 07:04:42 -04:00
|
|
|
)
|
2024-04-16 04:55:56 -04:00
|
|
|
|
|
|
|
if (historyRangesSupport) {
|
|
|
|
const historyUpdates = RangesManager.getHistoryUpdatesForAcceptedChanges({
|
|
|
|
docId,
|
|
|
|
acceptedChangeIds: changeIds,
|
|
|
|
changes: ranges.changes || [],
|
|
|
|
lines,
|
|
|
|
pathname,
|
|
|
|
projectHistoryId,
|
|
|
|
})
|
|
|
|
|
|
|
|
if (historyUpdates.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await ProjectHistoryRedisManager.promises.queueOps(
|
|
|
|
projectId,
|
|
|
|
...historyUpdates.map(op => JSON.stringify(op))
|
|
|
|
)
|
|
|
|
}
|
2020-05-06 06:09:33 -04:00
|
|
|
},
|
|
|
|
|
2024-04-09 05:15:06 -04:00
|
|
|
async updateCommentState(projectId, docId, commentId, userId, resolved) {
|
|
|
|
const { lines, version, pathname, historyRangesSupport } =
|
|
|
|
await DocumentManager.getDoc(projectId, docId)
|
|
|
|
|
|
|
|
if (lines == null || version == null) {
|
|
|
|
throw new Errors.NotFoundError(`document not found: ${docId}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (historyRangesSupport) {
|
2024-05-28 07:24:06 -04:00
|
|
|
await RedisManager.promises.updateCommentState(docId, commentId, resolved)
|
|
|
|
|
2024-04-09 05:15:06 -04:00
|
|
|
await ProjectHistoryRedisManager.promises.queueOps(
|
|
|
|
projectId,
|
|
|
|
JSON.stringify({
|
|
|
|
pathname,
|
|
|
|
commentId,
|
|
|
|
resolved,
|
|
|
|
meta: {
|
|
|
|
ts: new Date(),
|
|
|
|
user_id: userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async deleteComment(projectId, docId, commentId, userId) {
|
|
|
|
const { lines, version, ranges, pathname, historyRangesSupport } =
|
|
|
|
await DocumentManager.getDoc(projectId, docId)
|
|
|
|
if (lines == null || version == null) {
|
|
|
|
throw new Errors.NotFoundError(`document not found: ${docId}`)
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
const newRanges = RangesManager.deleteComment(commentId, ranges)
|
|
|
|
|
|
|
|
await RedisManager.promises.updateDocument(
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
2024-04-02 09:49:42 -04:00
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
[],
|
|
|
|
newRanges,
|
|
|
|
{}
|
2021-07-13 07:04:42 -04:00
|
|
|
)
|
2020-05-06 06:09:33 -04:00
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
if (historyRangesSupport) {
|
2024-05-28 07:24:06 -04:00
|
|
|
await RedisManager.promises.updateCommentState(docId, commentId, false)
|
2024-04-02 09:49:42 -04:00
|
|
|
await ProjectHistoryRedisManager.promises.queueOps(
|
|
|
|
projectId,
|
|
|
|
JSON.stringify({
|
|
|
|
pathname,
|
|
|
|
deleteComment: commentId,
|
|
|
|
meta: {
|
|
|
|
ts: new Date(),
|
|
|
|
user_id: userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|
2024-04-02 09:49:42 -04:00
|
|
|
},
|
2020-05-06 06:09:33 -04:00
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async renameDoc(projectId, docId, userId, update, projectHistoryId) {
|
|
|
|
await RedisManager.promises.renameDoc(
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
|
|
|
userId,
|
2020-05-06 06:09:33 -04:00
|
|
|
update,
|
2024-04-02 09:49:42 -04:00
|
|
|
projectHistoryId
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async getDocAndFlushIfOld(projectId, docId) {
|
|
|
|
const { lines, version, unflushedTime, alreadyLoaded } =
|
|
|
|
await DocumentManager.getDoc(projectId, docId)
|
|
|
|
|
|
|
|
// if doc was already loaded see if it needs to be flushed
|
|
|
|
if (
|
|
|
|
alreadyLoaded &&
|
|
|
|
unflushedTime != null &&
|
|
|
|
Date.now() - unflushedTime > MAX_UNFLUSHED_AGE
|
|
|
|
) {
|
|
|
|
await DocumentManager.flushDocIfLoaded(projectId, docId)
|
|
|
|
}
|
|
|
|
|
|
|
|
return { lines, version }
|
2020-05-06 06:09:33 -04:00
|
|
|
},
|
|
|
|
|
2024-06-18 10:00:00 -04:00
|
|
|
async resyncDocContents(projectId, docId, path, opts = {}) {
|
2021-11-30 08:26:20 -05:00
|
|
|
logger.debug({ projectId, docId, path }, 'start resyncing doc contents')
|
2024-05-28 07:24:06 -04:00
|
|
|
let {
|
|
|
|
lines,
|
|
|
|
ranges,
|
|
|
|
resolvedCommentIds,
|
|
|
|
version,
|
|
|
|
projectHistoryId,
|
|
|
|
historyRangesSupport,
|
|
|
|
} = await RedisManager.promises.getDoc(projectId, docId)
|
2024-04-02 09:49:42 -04:00
|
|
|
|
|
|
|
// To avoid issues where the same docId appears with different paths,
|
|
|
|
// we use the path from the resyncProjectStructure update. If we used
|
|
|
|
// the path from the getDoc call to web then the two occurences of the
|
|
|
|
// docId would map to the same path, and this would be rejected by
|
|
|
|
// project-history as an unexpected resyncDocContent update.
|
|
|
|
if (lines == null || version == null) {
|
|
|
|
logger.debug(
|
|
|
|
{ projectId, docId },
|
|
|
|
'resyncing doc contents - not found in redis - retrieving from web'
|
|
|
|
)
|
2024-05-28 07:24:06 -04:00
|
|
|
;({
|
|
|
|
lines,
|
|
|
|
ranges,
|
|
|
|
resolvedCommentIds,
|
|
|
|
version,
|
|
|
|
projectHistoryId,
|
|
|
|
historyRangesSupport,
|
|
|
|
} = await PersistenceManager.promises.getDoc(projectId, docId, {
|
|
|
|
peek: true,
|
|
|
|
}))
|
2024-04-02 09:49:42 -04:00
|
|
|
} else {
|
|
|
|
logger.debug(
|
|
|
|
{ projectId, docId },
|
|
|
|
'resyncing doc contents - doc in redis - will queue in redis'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-06-18 10:00:00 -04:00
|
|
|
if (opts.historyRangesMigration) {
|
|
|
|
historyRangesSupport = opts.historyRangesMigration === 'forwards'
|
|
|
|
}
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
await ProjectHistoryRedisManager.promises.queueResyncDocContent(
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
2024-04-02 09:49:42 -04:00
|
|
|
projectHistoryId,
|
2021-11-30 08:26:20 -05:00
|
|
|
docId,
|
2024-04-02 09:49:42 -04:00
|
|
|
lines,
|
2024-07-04 11:57:00 -04:00
|
|
|
ranges ?? {},
|
2024-05-28 07:24:06 -04:00
|
|
|
resolvedCommentIds,
|
2024-04-02 09:49:42 -04:00
|
|
|
version,
|
|
|
|
// use the path from the resyncProjectStructure update
|
2024-04-08 11:07:41 -04:00
|
|
|
path,
|
|
|
|
historyRangesSupport
|
2021-07-13 07:04:42 -04:00
|
|
|
)
|
2024-06-18 10:00:00 -04:00
|
|
|
|
|
|
|
if (opts.historyRangesMigration) {
|
|
|
|
await RedisManager.promises.setHistoryRangesSupportFlag(
|
|
|
|
docId,
|
|
|
|
historyRangesSupport
|
|
|
|
)
|
|
|
|
}
|
2020-05-06 06:09:33 -04:00
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async getDocWithLock(projectId, docId) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
return await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.getDoc,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
2024-04-02 09:49:42 -04:00
|
|
|
docId
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async getDocAndRecentOpsWithLock(projectId, docId, fromVersion) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
return await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.getDocAndRecentOps,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
2024-04-02 09:49:42 -04:00
|
|
|
fromVersion
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async getDocAndFlushIfOldWithLock(projectId, docId) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
return await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.getDocAndFlushIfOld,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
2024-04-02 09:49:42 -04:00
|
|
|
docId
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async setDocWithLock(projectId, docId, lines, source, userId, undoing) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
return await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.setDoc,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
2020-05-06 06:09:33 -04:00
|
|
|
lines,
|
|
|
|
source,
|
2021-11-30 08:26:20 -05:00
|
|
|
userId,
|
2024-04-02 09:49:42 -04:00
|
|
|
undoing
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async flushDocIfLoadedWithLock(projectId, docId) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
return await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.flushDocIfLoaded,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
2024-04-02 09:49:42 -04:00
|
|
|
docId
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async flushAndDeleteDocWithLock(projectId, docId, options) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
return await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.flushAndDeleteDoc,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
2024-04-02 09:49:42 -04:00
|
|
|
options
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async acceptChangesWithLock(projectId, docId, changeIds) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.acceptChanges,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
2024-04-02 09:49:42 -04:00
|
|
|
changeIds
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-09 05:15:06 -04:00
|
|
|
async updateCommentStateWithLock(
|
|
|
|
projectId,
|
|
|
|
docId,
|
|
|
|
threadId,
|
|
|
|
userId,
|
|
|
|
resolved
|
|
|
|
) {
|
|
|
|
const UpdateManager = require('./UpdateManager')
|
|
|
|
await UpdateManager.promises.lockUpdatesAndDo(
|
|
|
|
DocumentManager.updateCommentState,
|
|
|
|
projectId,
|
|
|
|
docId,
|
|
|
|
threadId,
|
|
|
|
userId,
|
|
|
|
resolved
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async deleteCommentWithLock(projectId, docId, threadId, userId) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.deleteComment,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
|
|
|
threadId,
|
2024-04-02 09:49:42 -04:00
|
|
|
userId
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
async renameDocWithLock(projectId, docId, userId, update, projectHistoryId) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.renameDoc,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
|
|
|
userId,
|
2020-05-06 06:09:33 -04:00
|
|
|
update,
|
2024-04-02 09:49:42 -04:00
|
|
|
projectHistoryId
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2024-06-18 10:00:00 -04:00
|
|
|
async resyncDocContentsWithLock(projectId, docId, path, opts) {
|
2020-05-06 06:09:33 -04:00
|
|
|
const UpdateManager = require('./UpdateManager')
|
2024-04-02 09:49:42 -04:00
|
|
|
await UpdateManager.promises.lockUpdatesAndDo(
|
2020-05-06 06:09:33 -04:00
|
|
|
DocumentManager.resyncDocContents,
|
2021-11-30 08:26:20 -05:00
|
|
|
projectId,
|
|
|
|
docId,
|
2021-11-22 09:15:36 -05:00
|
|
|
path,
|
2024-06-18 10:00:00 -04:00
|
|
|
opts
|
2020-05-06 06:09:33 -04:00
|
|
|
)
|
2021-07-13 07:04:42 -04:00
|
|
|
},
|
2020-05-06 06:09:33 -04:00
|
|
|
}
|
2024-01-30 10:35:54 -05:00
|
|
|
|
2024-04-02 09:49:42 -04:00
|
|
|
module.exports = {
|
|
|
|
...callbackifyAll(DocumentManager, {
|
|
|
|
multiResult: {
|
|
|
|
getDoc: [
|
|
|
|
'lines',
|
|
|
|
'version',
|
|
|
|
'ranges',
|
|
|
|
'pathname',
|
|
|
|
'projectHistoryId',
|
|
|
|
'unflushedTime',
|
|
|
|
'alreadyLoaded',
|
|
|
|
'historyRangesSupport',
|
|
|
|
],
|
|
|
|
getDocWithLock: [
|
|
|
|
'lines',
|
|
|
|
'version',
|
|
|
|
'ranges',
|
|
|
|
'pathname',
|
|
|
|
'projectHistoryId',
|
|
|
|
'unflushedTime',
|
|
|
|
'alreadyLoaded',
|
|
|
|
'historyRangesSupport',
|
|
|
|
],
|
|
|
|
getDocAndFlushIfOld: ['lines', 'version'],
|
|
|
|
getDocAndFlushIfOldWithLock: ['lines', 'version'],
|
|
|
|
getDocAndRecentOps: [
|
|
|
|
'lines',
|
|
|
|
'version',
|
|
|
|
'ops',
|
|
|
|
'ranges',
|
|
|
|
'pathname',
|
|
|
|
'projectHistoryId',
|
|
|
|
],
|
|
|
|
getDocAndRecentOpsWithLock: [
|
|
|
|
'lines',
|
|
|
|
'version',
|
|
|
|
'ops',
|
|
|
|
'ranges',
|
|
|
|
'pathname',
|
|
|
|
'projectHistoryId',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
promises: DocumentManager,
|
|
|
|
}
|