DocumentManager.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. const { callbackifyAll } = require('@overleaf/promise-utils')
  2. const RedisManager = require('./RedisManager')
  3. const ProjectHistoryRedisManager = require('./ProjectHistoryRedisManager')
  4. const PersistenceManager = require('./PersistenceManager')
  5. const DiffCodec = require('./DiffCodec')
  6. const logger = require('@overleaf/logger')
  7. const Metrics = require('./Metrics')
  8. const HistoryManager = require('./HistoryManager')
  9. const Errors = require('./Errors')
  10. const RangesManager = require('./RangesManager')
  11. const { extractOriginOrSource } = require('./Utils')
  12. const { getTotalSizeOfLines } = require('./Limits')
  13. const Settings = require('@overleaf/settings')
  14. const { StringFileData } = require('overleaf-editor-core')
  15. const MAX_UNFLUSHED_AGE = Settings.maxUnflushedAgeMs // document should be flushed to mongo this time after a change
  16. const DocumentManager = {
  17. /**
  18. * @param {string} projectId
  19. * @param {string} docId
  20. * @return {Promise<{lines: (string[] | StringFileRawData), version: number, ranges: Ranges, resolvedCommentIds: any[], pathname: string, projectHistoryId: string, unflushedTime: any, alreadyLoaded: boolean, historyRangesSupport: boolean, type: OTType}>}
  21. */
  22. async getDoc(projectId, docId) {
  23. const {
  24. lines,
  25. version,
  26. ranges,
  27. resolvedCommentIds,
  28. pathname,
  29. projectHistoryId,
  30. unflushedTime,
  31. historyRangesSupport,
  32. } = await RedisManager.promises.getDoc(projectId, docId)
  33. if (lines == null || version == null) {
  34. logger.debug(
  35. { projectId, docId },
  36. 'doc not in redis so getting from persistence API'
  37. )
  38. const {
  39. lines,
  40. version,
  41. ranges,
  42. resolvedCommentIds,
  43. pathname,
  44. projectHistoryId,
  45. historyRangesSupport,
  46. } = await PersistenceManager.promises.getDoc(projectId, docId)
  47. logger.debug(
  48. {
  49. projectId,
  50. docId,
  51. lines,
  52. ranges,
  53. resolvedCommentIds,
  54. version,
  55. pathname,
  56. projectHistoryId,
  57. historyRangesSupport,
  58. },
  59. 'got doc from persistence API'
  60. )
  61. await RedisManager.promises.putDocInMemory(
  62. projectId,
  63. docId,
  64. lines,
  65. version,
  66. ranges,
  67. resolvedCommentIds,
  68. pathname,
  69. projectHistoryId,
  70. historyRangesSupport
  71. )
  72. return {
  73. lines,
  74. version,
  75. ranges: ranges || {},
  76. resolvedCommentIds,
  77. pathname,
  78. projectHistoryId,
  79. unflushedTime: null,
  80. alreadyLoaded: false,
  81. historyRangesSupport,
  82. type: Array.isArray(lines) ? 'sharejs-text-ot' : 'history-ot',
  83. }
  84. } else {
  85. return {
  86. lines,
  87. version,
  88. ranges,
  89. pathname,
  90. projectHistoryId,
  91. resolvedCommentIds,
  92. unflushedTime,
  93. alreadyLoaded: true,
  94. historyRangesSupport,
  95. type: Array.isArray(lines) ? 'sharejs-text-ot' : 'history-ot',
  96. }
  97. }
  98. },
  99. async getDocAndRecentOps(projectId, docId, fromVersion) {
  100. const { lines, version, ranges, pathname, projectHistoryId, type } =
  101. await DocumentManager.getDoc(projectId, docId)
  102. if (fromVersion === -1) {
  103. return {
  104. lines,
  105. version,
  106. ops: [],
  107. ranges,
  108. pathname,
  109. projectHistoryId,
  110. type,
  111. }
  112. } else {
  113. const ops = await RedisManager.promises.getPreviousDocOps(
  114. docId,
  115. fromVersion,
  116. version
  117. )
  118. return {
  119. lines,
  120. version,
  121. ops,
  122. ranges,
  123. pathname,
  124. projectHistoryId,
  125. type,
  126. }
  127. }
  128. },
  129. async appendToDoc(projectId, docId, linesToAppend, originOrSource, userId) {
  130. let { lines: currentLines, type } = await DocumentManager.getDoc(
  131. projectId,
  132. docId
  133. )
  134. if (type === 'history-ot') {
  135. const file = StringFileData.fromRaw(currentLines)
  136. // TODO(24596): tc support for history-ot
  137. currentLines = file.getLines()
  138. }
  139. const currentLineSize = getTotalSizeOfLines(currentLines)
  140. const addedSize = getTotalSizeOfLines(linesToAppend)
  141. const newlineSize = '\n'.length
  142. if (currentLineSize + newlineSize + addedSize > Settings.max_doc_length) {
  143. throw new Errors.FileTooLargeError(
  144. 'doc would become too large if appending this text'
  145. )
  146. }
  147. return await DocumentManager.setDoc(
  148. projectId,
  149. docId,
  150. currentLines.concat(linesToAppend),
  151. originOrSource,
  152. userId,
  153. false,
  154. false
  155. )
  156. },
  157. async setDoc(
  158. projectId,
  159. docId,
  160. newLines,
  161. originOrSource,
  162. userId,
  163. undoing,
  164. external
  165. ) {
  166. if (newLines == null) {
  167. throw new Error('No lines were provided to setDoc')
  168. }
  169. // Circular dependencies. Import at runtime.
  170. const HistoryOTUpdateManager = require('./HistoryOTUpdateManager')
  171. const UpdateManager = require('./UpdateManager')
  172. const {
  173. lines: oldLines,
  174. version,
  175. alreadyLoaded,
  176. type,
  177. } = await DocumentManager.getDoc(projectId, docId)
  178. logger.debug(
  179. { docId, projectId, oldLines, newLines },
  180. 'setting a document via http'
  181. )
  182. let op
  183. if (type === 'history-ot') {
  184. const file = StringFileData.fromRaw(oldLines)
  185. const operation = DiffCodec.diffAsHistoryOTEditOperation(
  186. file,
  187. newLines.join('\n')
  188. )
  189. if (operation.isNoop()) {
  190. op = []
  191. } else {
  192. op = [operation.toJSON()]
  193. }
  194. } else {
  195. op = DiffCodec.diffAsShareJsOp(oldLines, newLines)
  196. if (undoing) {
  197. for (const o of op || []) {
  198. o.u = true
  199. } // Turn on undo flag for each op for track changes
  200. }
  201. }
  202. const { origin, source } = extractOriginOrSource(originOrSource)
  203. const update = {
  204. doc: docId,
  205. op,
  206. v: version,
  207. meta: {
  208. user_id: userId,
  209. },
  210. }
  211. if (external) {
  212. update.meta.type = 'external'
  213. }
  214. if (origin) {
  215. update.meta.origin = origin
  216. } else if (source) {
  217. update.meta.source = source
  218. }
  219. // Keep track of external updates, whether they are for live documents
  220. // (flush) or unloaded documents (evict), and whether the update is a no-op.
  221. Metrics.inc('external-update', 1, {
  222. status: op.length > 0 ? 'diff' : 'noop',
  223. method: alreadyLoaded ? 'flush' : 'evict',
  224. path: source,
  225. })
  226. // Do not notify the frontend about a noop update.
  227. // We still want to execute the code below
  228. // to evict the doc if we loaded it into redis for
  229. // this update, otherwise the doc would never be
  230. // removed from redis.
  231. if (op.length > 0) {
  232. if (type === 'history-ot') {
  233. await HistoryOTUpdateManager.applyUpdate(projectId, docId, update)
  234. } else {
  235. await UpdateManager.promises.applyUpdate(projectId, docId, update)
  236. }
  237. }
  238. // If the document was loaded already, then someone has it open
  239. // in a project, and the usual flushing mechanism will happen.
  240. // Otherwise we should remove it immediately since nothing else
  241. // is using it.
  242. if (alreadyLoaded) {
  243. return await DocumentManager.flushDocIfLoaded(projectId, docId)
  244. } else {
  245. try {
  246. return await DocumentManager.flushAndDeleteDoc(projectId, docId, {})
  247. } finally {
  248. // There is no harm in flushing project history if the previous
  249. // call failed and sometimes it is required
  250. HistoryManager.flushProjectChangesAsync(projectId)
  251. }
  252. }
  253. },
  254. async flushDocIfLoaded(projectId, docId) {
  255. let {
  256. lines,
  257. version,
  258. ranges,
  259. unflushedTime,
  260. lastUpdatedAt,
  261. lastUpdatedBy,
  262. } = await RedisManager.promises.getDoc(projectId, docId)
  263. if (lines == null || version == null) {
  264. Metrics.inc('flush-doc-if-loaded', 1, { status: 'not-loaded' })
  265. logger.debug({ projectId, docId }, 'doc is not loaded so not flushing')
  266. // TODO: return a flag to bail out, as we go on to remove doc from memory?
  267. return
  268. } else if (unflushedTime == null) {
  269. Metrics.inc('flush-doc-if-loaded', 1, { status: 'unmodified' })
  270. logger.debug({ projectId, docId }, 'doc is not modified so not flushing')
  271. return
  272. }
  273. logger.debug({ projectId, docId, version }, 'flushing doc')
  274. Metrics.inc('flush-doc-if-loaded', 1, { status: 'modified' })
  275. if (!Array.isArray(lines)) {
  276. const file = StringFileData.fromRaw(lines)
  277. // TODO(24596): tc support for history-ot
  278. lines = file.getLines()
  279. }
  280. const result = await PersistenceManager.promises.setDoc(
  281. projectId,
  282. docId,
  283. lines,
  284. version,
  285. ranges,
  286. lastUpdatedAt,
  287. lastUpdatedBy || null
  288. )
  289. await RedisManager.promises.clearUnflushedTime(docId)
  290. return result
  291. },
  292. async flushAndDeleteDoc(projectId, docId, options) {
  293. let result
  294. try {
  295. result = await DocumentManager.flushDocIfLoaded(projectId, docId)
  296. } catch (error) {
  297. if (options.ignoreFlushErrors) {
  298. logger.warn(
  299. { projectId, docId, err: error },
  300. 'ignoring flush error while deleting document'
  301. )
  302. } else {
  303. throw error
  304. }
  305. }
  306. await RedisManager.promises.removeDocFromMemory(projectId, docId)
  307. return result
  308. },
  309. async acceptChanges(projectId, docId, changeIds) {
  310. if (changeIds == null) {
  311. changeIds = []
  312. }
  313. let changeContributors = []
  314. const {
  315. lines,
  316. version,
  317. ranges,
  318. pathname,
  319. projectHistoryId,
  320. historyRangesSupport,
  321. } = await DocumentManager.getDoc(projectId, docId)
  322. if (lines == null || version == null) {
  323. throw new Errors.NotFoundError(`document not found: ${docId}`)
  324. }
  325. // TODO(24596): tc support for history-ot
  326. const newRanges = RangesManager.acceptChanges(
  327. projectId,
  328. docId,
  329. changeIds,
  330. ranges,
  331. lines
  332. )
  333. await RedisManager.promises.updateDocument(
  334. projectId,
  335. docId,
  336. lines,
  337. version,
  338. [],
  339. newRanges,
  340. {}
  341. )
  342. if (historyRangesSupport) {
  343. const historyUpdates = RangesManager.getHistoryUpdatesForAcceptedChanges({
  344. docId,
  345. acceptedChangeIds: changeIds,
  346. changes: ranges.changes || [],
  347. lines,
  348. pathname,
  349. projectHistoryId,
  350. })
  351. if (historyUpdates.length === 0) {
  352. return changeContributors
  353. }
  354. await ProjectHistoryRedisManager.promises.queueOps(
  355. projectId,
  356. ...historyUpdates.map(op => JSON.stringify(op))
  357. )
  358. }
  359. changeContributors = (ranges.changes || [])
  360. .filter(change => changeIds.includes(change.id))
  361. .map(change => change?.metadata?.user_id)
  362. .filter(userId => userId)
  363. return changeContributors
  364. },
  365. async rejectChanges(projectId, docId, changeIds, userId) {
  366. const UpdateManager = require('./UpdateManager')
  367. const HistoryOTUpdateManager = require('./HistoryOTUpdateManager')
  368. const { lines, version, ranges } = await DocumentManager.getDoc(
  369. projectId,
  370. docId
  371. )
  372. if (lines == null || version == null) {
  373. throw new Errors.NotFoundError(`document not found: ${docId}`)
  374. }
  375. const changesToReject = ranges.changes
  376. ? ranges.changes.filter(change => changeIds.includes(change.id))
  377. : []
  378. // Apply inverted operations for rejected changes (based on reject-changes.ts logic)
  379. // Sort changes in reverse order by position to avoid conflicts
  380. changesToReject.sort((a, b) => b.op.p - a.op.p)
  381. const ops = []
  382. for (const change of changesToReject) {
  383. if (change.op.i) {
  384. const deleteOp = {
  385. p: change.op.p,
  386. d: change.op.i,
  387. u: true,
  388. }
  389. ops.push(deleteOp)
  390. } else if (change.op.d) {
  391. const insertOp = {
  392. p: change.op.p,
  393. i: change.op.d,
  394. u: true,
  395. }
  396. ops.push(insertOp)
  397. }
  398. }
  399. const update = {
  400. doc: docId,
  401. op: ops,
  402. v: version,
  403. meta: {
  404. user_id: userId,
  405. ts: new Date().toISOString(),
  406. },
  407. }
  408. if (HistoryOTUpdateManager.isHistoryOTEditOperationUpdate(update)) {
  409. await HistoryOTUpdateManager.applyUpdate(projectId, docId, update)
  410. } else {
  411. await UpdateManager.promises.applyUpdate(projectId, docId, update)
  412. }
  413. return { rejectedChangeIds: changesToReject.map(c => c.id) }
  414. },
  415. async updateCommentState(projectId, docId, commentId, userId, resolved) {
  416. const { lines, version, pathname, historyRangesSupport } =
  417. await DocumentManager.getDoc(projectId, docId)
  418. if (lines == null || version == null) {
  419. throw new Errors.NotFoundError(`document not found: ${docId}`)
  420. }
  421. if (historyRangesSupport) {
  422. await RedisManager.promises.updateCommentState(docId, commentId, resolved)
  423. await ProjectHistoryRedisManager.promises.queueOps(
  424. projectId,
  425. JSON.stringify({
  426. pathname,
  427. commentId,
  428. resolved,
  429. meta: {
  430. ts: new Date(),
  431. user_id: userId,
  432. },
  433. })
  434. )
  435. }
  436. },
  437. async getComment(projectId, docId, commentId) {
  438. // TODO(24596): tc support for history-ot
  439. const { ranges } = await DocumentManager.getDoc(projectId, docId)
  440. const comment = ranges?.comments?.find(comment => comment.id === commentId)
  441. if (!comment) {
  442. throw new Errors.NotFoundError({
  443. message: 'comment not found',
  444. info: { commentId },
  445. })
  446. }
  447. return comment
  448. },
  449. async deleteComment(projectId, docId, commentId, userId) {
  450. const { lines, version, ranges, pathname, historyRangesSupport } =
  451. await DocumentManager.getDoc(projectId, docId)
  452. if (lines == null || version == null) {
  453. throw new Errors.NotFoundError(`document not found: ${docId}`)
  454. }
  455. // TODO(24596): tc support for history-ot
  456. const newRanges = RangesManager.deleteComment(commentId, ranges)
  457. await RedisManager.promises.updateDocument(
  458. projectId,
  459. docId,
  460. lines,
  461. version,
  462. [],
  463. newRanges,
  464. {}
  465. )
  466. if (historyRangesSupport) {
  467. await RedisManager.promises.updateCommentState(docId, commentId, false)
  468. await ProjectHistoryRedisManager.promises.queueOps(
  469. projectId,
  470. JSON.stringify({
  471. pathname,
  472. deleteComment: commentId,
  473. meta: {
  474. ts: new Date(),
  475. user_id: userId,
  476. },
  477. })
  478. )
  479. }
  480. },
  481. async renameDoc(projectId, docId, userId, update, projectHistoryId) {
  482. await RedisManager.promises.renameDoc(
  483. projectId,
  484. docId,
  485. userId,
  486. update,
  487. projectHistoryId
  488. )
  489. },
  490. async getDocAndFlushIfOld(projectId, docId) {
  491. let { lines, version, unflushedTime, alreadyLoaded } =
  492. await DocumentManager.getDoc(projectId, docId)
  493. // if doc was already loaded see if it needs to be flushed
  494. if (
  495. alreadyLoaded &&
  496. unflushedTime != null &&
  497. Date.now() - unflushedTime > MAX_UNFLUSHED_AGE
  498. ) {
  499. await DocumentManager.flushDocIfLoaded(projectId, docId)
  500. }
  501. if (!Array.isArray(lines)) {
  502. const file = StringFileData.fromRaw(lines)
  503. // TODO(24596): tc support for history-ot
  504. lines = file.getLines()
  505. }
  506. return { lines, version }
  507. },
  508. async resyncDocContents(projectId, docId, path, opts = {}) {
  509. logger.debug({ projectId, docId, path }, 'start resyncing doc contents')
  510. let {
  511. lines,
  512. ranges,
  513. resolvedCommentIds,
  514. version,
  515. projectHistoryId,
  516. historyRangesSupport,
  517. } = await RedisManager.promises.getDoc(projectId, docId)
  518. // To avoid issues where the same docId appears with different paths,
  519. // we use the path from the resyncProjectStructure update. If we used
  520. // the path from the getDoc call to web then the two occurences of the
  521. // docId would map to the same path, and this would be rejected by
  522. // project-history as an unexpected resyncDocContent update.
  523. if (lines == null || version == null) {
  524. logger.debug(
  525. { projectId, docId },
  526. 'resyncing doc contents - not found in redis - retrieving from web'
  527. )
  528. ;({
  529. lines,
  530. ranges,
  531. resolvedCommentIds,
  532. version,
  533. projectHistoryId,
  534. historyRangesSupport,
  535. } = await PersistenceManager.promises.getDoc(projectId, docId, {
  536. peek: true,
  537. }))
  538. } else {
  539. logger.debug(
  540. { projectId, docId },
  541. 'resyncing doc contents - doc in redis - will queue in redis'
  542. )
  543. }
  544. if (opts.historyRangesMigration) {
  545. historyRangesSupport = opts.historyRangesMigration === 'forwards'
  546. }
  547. await ProjectHistoryRedisManager.promises.queueResyncDocContent(
  548. projectId,
  549. projectHistoryId,
  550. docId,
  551. lines,
  552. ranges ?? {},
  553. resolvedCommentIds,
  554. version,
  555. // use the path from the resyncProjectStructure update
  556. path,
  557. historyRangesSupport
  558. )
  559. if (opts.historyRangesMigration) {
  560. await RedisManager.promises.setHistoryRangesSupportFlag(
  561. docId,
  562. historyRangesSupport
  563. )
  564. }
  565. },
  566. async getDocWithLock(projectId, docId) {
  567. const UpdateManager = require('./UpdateManager')
  568. return await UpdateManager.promises.lockUpdatesAndDo(
  569. DocumentManager.getDoc,
  570. projectId,
  571. docId
  572. )
  573. },
  574. async getCommentWithLock(projectId, docId, commentId) {
  575. const UpdateManager = require('./UpdateManager')
  576. return await UpdateManager.promises.lockUpdatesAndDo(
  577. DocumentManager.getComment,
  578. projectId,
  579. docId,
  580. commentId
  581. )
  582. },
  583. async getDocAndRecentOpsWithLock(projectId, docId, fromVersion) {
  584. const UpdateManager = require('./UpdateManager')
  585. return await UpdateManager.promises.lockUpdatesAndDo(
  586. DocumentManager.getDocAndRecentOps,
  587. projectId,
  588. docId,
  589. fromVersion
  590. )
  591. },
  592. async getDocAndFlushIfOldWithLock(projectId, docId) {
  593. const UpdateManager = require('./UpdateManager')
  594. return await UpdateManager.promises.lockUpdatesAndDo(
  595. DocumentManager.getDocAndFlushIfOld,
  596. projectId,
  597. docId
  598. )
  599. },
  600. async setDocWithLock(
  601. projectId,
  602. docId,
  603. lines,
  604. source,
  605. userId,
  606. undoing,
  607. external
  608. ) {
  609. const UpdateManager = require('./UpdateManager')
  610. return await UpdateManager.promises.lockUpdatesAndDo(
  611. DocumentManager.setDoc,
  612. projectId,
  613. docId,
  614. lines,
  615. source,
  616. userId,
  617. undoing,
  618. external
  619. )
  620. },
  621. async appendToDocWithLock(projectId, docId, lines, source, userId) {
  622. const UpdateManager = require('./UpdateManager')
  623. return await UpdateManager.promises.lockUpdatesAndDo(
  624. DocumentManager.appendToDoc,
  625. projectId,
  626. docId,
  627. lines,
  628. source,
  629. userId
  630. )
  631. },
  632. async flushDocIfLoadedWithLock(projectId, docId) {
  633. const UpdateManager = require('./UpdateManager')
  634. return await UpdateManager.promises.lockUpdatesAndDo(
  635. DocumentManager.flushDocIfLoaded,
  636. projectId,
  637. docId
  638. )
  639. },
  640. async flushAndDeleteDocWithLock(projectId, docId, options) {
  641. const UpdateManager = require('./UpdateManager')
  642. return await UpdateManager.promises.lockUpdatesAndDo(
  643. DocumentManager.flushAndDeleteDoc,
  644. projectId,
  645. docId,
  646. options
  647. )
  648. },
  649. async acceptChangesWithLock(projectId, docId, changeIds) {
  650. const UpdateManager = require('./UpdateManager')
  651. const changeContributors = await UpdateManager.promises.lockUpdatesAndDo(
  652. DocumentManager.acceptChanges,
  653. projectId,
  654. docId,
  655. changeIds
  656. )
  657. return changeContributors
  658. },
  659. async rejectChangesWithLock(projectId, docId, changeIds, userId) {
  660. const UpdateManager = require('./UpdateManager')
  661. return await UpdateManager.promises.lockUpdatesAndDo(
  662. DocumentManager.rejectChanges,
  663. projectId,
  664. docId,
  665. changeIds,
  666. userId
  667. )
  668. },
  669. async updateCommentStateWithLock(
  670. projectId,
  671. docId,
  672. threadId,
  673. userId,
  674. resolved
  675. ) {
  676. const UpdateManager = require('./UpdateManager')
  677. await UpdateManager.promises.lockUpdatesAndDo(
  678. DocumentManager.updateCommentState,
  679. projectId,
  680. docId,
  681. threadId,
  682. userId,
  683. resolved
  684. )
  685. },
  686. async deleteCommentWithLock(projectId, docId, threadId, userId) {
  687. const UpdateManager = require('./UpdateManager')
  688. await UpdateManager.promises.lockUpdatesAndDo(
  689. DocumentManager.deleteComment,
  690. projectId,
  691. docId,
  692. threadId,
  693. userId
  694. )
  695. },
  696. async renameDocWithLock(projectId, docId, userId, update, projectHistoryId) {
  697. const UpdateManager = require('./UpdateManager')
  698. await UpdateManager.promises.lockUpdatesAndDo(
  699. DocumentManager.renameDoc,
  700. projectId,
  701. docId,
  702. userId,
  703. update,
  704. projectHistoryId
  705. )
  706. },
  707. async resyncDocContentsWithLock(projectId, docId, path, opts) {
  708. const UpdateManager = require('./UpdateManager')
  709. await UpdateManager.promises.lockUpdatesAndDo(
  710. DocumentManager.resyncDocContents,
  711. projectId,
  712. docId,
  713. path,
  714. opts
  715. )
  716. },
  717. }
  718. module.exports = {
  719. ...callbackifyAll(DocumentManager, {
  720. multiResult: {
  721. getDoc: [
  722. 'lines',
  723. 'version',
  724. 'ranges',
  725. 'pathname',
  726. 'projectHistoryId',
  727. 'unflushedTime',
  728. 'alreadyLoaded',
  729. 'historyRangesSupport',
  730. ],
  731. getDocWithLock: [
  732. 'lines',
  733. 'version',
  734. 'ranges',
  735. 'pathname',
  736. 'projectHistoryId',
  737. 'unflushedTime',
  738. 'alreadyLoaded',
  739. 'historyRangesSupport',
  740. ],
  741. getDocAndFlushIfOld: ['lines', 'version'],
  742. getDocAndFlushIfOldWithLock: ['lines', 'version'],
  743. getDocAndRecentOps: [
  744. 'lines',
  745. 'version',
  746. 'ops',
  747. 'ranges',
  748. 'pathname',
  749. 'projectHistoryId',
  750. 'type',
  751. ],
  752. getDocAndRecentOpsWithLock: [
  753. 'lines',
  754. 'version',
  755. 'ops',
  756. 'ranges',
  757. 'pathname',
  758. 'projectHistoryId',
  759. 'type',
  760. ],
  761. },
  762. }),
  763. promises: DocumentManager,
  764. }