Merge pull request #17396 from overleaf/mj-version-filtering

[overleaf-editor-core+project-history] Filter tracked changes when fetching files

GitOrigin-RevId: 935e4c4712f31b77070aec545a849fc6fefedcd9
This commit is contained in:
Mathias Jakobsen
2024-04-05 11:27:00 +01:00
committed by Copybot
parent 178485715f
commit 815c29cf82
9 changed files with 235 additions and 53 deletions

View File

@@ -1,3 +1,4 @@
// @ts-check
'use strict'
const _ = require('lodash')
@@ -11,6 +12,7 @@ const StringFileData = require('./file_data/string_file_data')
/**
* @typedef {import("./blob")} Blob
* @typedef {import("./types").BlobStore} BlobStore
* @typedef {import("./types").ReadonlyBlobStore} ReadonlyBlobStore
* @typedef {import("./types").StringFileRawData} StringFileRawData
* @typedef {import("./types").CommentRawData} CommentRawData
* @typedef {import("./operation/text_operation")} TextOperation
@@ -97,7 +99,7 @@ class File {
/**
* @param {Blob} blob
* @param {Blob} [blob]
* @param {Blob} [rangesBlob]
* @param {Object} [metadata]
* @return {File}
*/
@@ -213,7 +215,7 @@ class File {
* @return {File} a new object of the same type
*/
clone() {
return File.fromRaw(this.toRaw())
return /** @type {File} */ (File.fromRaw(this.toRaw()))
}
/**
@@ -222,7 +224,7 @@ class File {
* operation.
*
* @param {string} kind
* @param {BlobStore} blobStore
* @param {ReadonlyBlobStore} blobStore
* @return {Promise.<File>} for this
*/
async load(kind, blobStore) {

View File

@@ -15,6 +15,7 @@ let StringFileData = null
/**
* @typedef {import("../types").BlobStore} BlobStore
* @typedef {import("../types").ReadonlyBlobStore} ReadonlyBlobStore
* @typedef {import("../operation/edit_operation")} EditOperation
* @typedef {import("../types").CommentRawData} CommentRawData
*/
@@ -131,7 +132,7 @@ class FileData {
/**
* @function
* @param {BlobStore} blobStore
* @param {ReadonlyBlobStore} blobStore
* @return {Promise<FileData>}
* @abstract
* @see FileData#load
@@ -142,7 +143,7 @@ class FileData {
/**
* @function
* @param {BlobStore} blobStore
* @param {ReadonlyBlobStore} blobStore
* @return {Promise<FileData>}
* @abstract
* @see FileData#load
@@ -153,7 +154,7 @@ class FileData {
/**
* @function
* @param {BlobStore} blobStore
* @param {ReadonlyBlobStore} blobStore
* @return {Promise<FileData>}
* @abstract
* @see FileData#load
@@ -165,7 +166,7 @@ class FileData {
/**
* @see File#load
* @param {string} kind
* @param {BlobStore} blobStore
* @param {ReadonlyBlobStore} blobStore
* @return {Promise<FileData>}
*/
async load(kind, blobStore) {

View File

@@ -12,6 +12,7 @@ const EditOperationBuilder = require('../operation/edit_operation_builder')
/**
* @typedef {import('../types').BlobStore} BlobStore
* @typedef {import('../types').ReadonlyBlobStore} ReadonlyBlobStore
* @typedef {import('../types').RangesBlob} RangesBlob
*/
@@ -106,7 +107,7 @@ class LazyStringFileData extends FileData {
/**
* @inheritdoc
* @param {BlobStore} blobStore
* @param {ReadonlyBlobStore} blobStore
* @returns {Promise<EagerStringFileData>}
*/
async toEager(blobStore) {

View File

@@ -1,3 +1,4 @@
// @ts-check
'use strict'
const _ = require('lodash')
@@ -64,11 +65,12 @@ class FileMap {
static FileNotFoundError = FileNotFoundError
/**
* @param {Object.<String, File>} files
* @param {Record<String, File | null>} files
*/
constructor(files) {
// create bare object for use as Map
// http://ryanmorr.com/true-hash-maps-in-javascript/
/** @type {Record<String, File | null>} */
this.files = Object.create(null)
_.assign(this.files, files)
checkPathnamesAreUnique(this.files)
@@ -221,8 +223,9 @@ class FileMap {
/**
* Map the files in this map to new values.
* @param {function} iteratee
* @return {Object}
* @template T
* @param {(file: File | null) => T} iteratee
* @return {Record<String, T>}
*/
map(iteratee) {
return _.mapValues(this.files, iteratee)

View File

@@ -10,6 +10,7 @@ const FILE_LOAD_CONCURRENCY = 50
/**
* @typedef {import("./types").BlobStore} BlobStore
* @typedef {import("./types").ReadonlyBlobStore} ReadonlyBlobStore
* @typedef {import("./change")} Change
* @typedef {import("./operation/text_operation")} TextOperation
*/
@@ -167,7 +168,7 @@ class Snapshot {
* Ignore recoverable errors (caused by historical bad data) unless opts.strict is true
*
* @param {Change[]} changes
* @param {object} opts
* @param {object} [opts]
* @param {boolean} opts.strict - do not ignore recoverable errors
*/
applyAll(changes, opts) {
@@ -196,7 +197,7 @@ class Snapshot {
* Load all of the files in this snapshot.
*
* @param {string} kind see {File#load}
* @param {BlobStore} blobStore
* @param {ReadonlyBlobStore} blobStore
* @return {Promise<Object>} an object where keys are the pathnames and
* values are the files in the snapshot
*/

View File

@@ -8,6 +8,8 @@ export type BlobStore = {
getObject<T = unknown>(hash: string): Promise<T>
}
export type ReadonlyBlobStore = Pick<BlobStore, 'getString' | 'getObject'>
export type RangesBlob = {
comments: CommentsListRawData
trackedChanges: TrackedChangeRawData[]