mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[web] extend history debugging with estimate on snapshot size (#32502)
GitOrigin-RevId: 6ee75d227c0d093e4698324f6cc018b077076730
This commit is contained in:
@@ -123,6 +123,19 @@ class File {
|
|||||||
return rawFileData
|
return rawFileData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Record<string, number>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
const stats = this.data.toStats()
|
||||||
|
if (!_.isEmpty(this.metadata)) {
|
||||||
|
stats.nMeta = 1
|
||||||
|
// Note: Buffer does not exist in frontend. Use string length instead.
|
||||||
|
stats.metaSize = JSON.stringify(this.metadata).length
|
||||||
|
}
|
||||||
|
return stats
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hexadecimal SHA-1 hash of the file's content, if known.
|
* Hexadecimal SHA-1 hash of the file's content, if known.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -33,6 +33,16 @@ class BinaryFileData extends FileData {
|
|||||||
return new BinaryFileData(raw.hash, raw.byteLength)
|
return new BinaryFileData(raw.hash, raw.byteLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Record<string, number>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
return {
|
||||||
|
hashes: 1,
|
||||||
|
byteLength: this.byteLength,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
* @returns {RawBinaryFileData}
|
* @returns {RawBinaryFileData}
|
||||||
|
|||||||
@@ -54,6 +54,15 @@ class HashFileData extends FileData {
|
|||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Record<string, number>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
return {
|
||||||
|
hashes: 1 + (this.rangesHash ? 1 : 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
|
|||||||
@@ -36,6 +36,15 @@ class HollowBinaryFileData extends FileData {
|
|||||||
return { byteLength: this.byteLength }
|
return { byteLength: this.byteLength }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Record<string, number>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
return {
|
||||||
|
byteLength: this.byteLength,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
getByteLength() {
|
getByteLength() {
|
||||||
return this.byteLength
|
return this.byteLength
|
||||||
|
|||||||
@@ -42,6 +42,15 @@ class HollowStringFileData extends FileData {
|
|||||||
return { stringLength: this.stringLength }
|
return { stringLength: this.stringLength }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Record<string, number>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
return {
|
||||||
|
stringLength: this.stringLength,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
getStringLength() {
|
getStringLength() {
|
||||||
return this.stringLength
|
return this.stringLength
|
||||||
|
|||||||
@@ -81,6 +81,13 @@ class FileData {
|
|||||||
throw new Error('FileData: toRaw not implemented')
|
throw new Error('FileData: toRaw not implemented')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Record<string, number>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
throw new Error('FileData: toStats not implemented')
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see File#getHash
|
* @see File#getHash
|
||||||
* @return {string | null | undefined}
|
* @return {string | null | undefined}
|
||||||
|
|||||||
@@ -71,6 +71,25 @@ class LazyStringFileData extends FileData {
|
|||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Record<string, number>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
return {
|
||||||
|
hashes: 1 + (this.rangesHash ? 1 : 0),
|
||||||
|
stringLength: this.stringLength,
|
||||||
|
nOperations: this.operations.length,
|
||||||
|
operationsSize:
|
||||||
|
this.operations.length > 0
|
||||||
|
? this.operations.reduce(
|
||||||
|
// Note: Buffer does not exist in frontend. Use string length instead.
|
||||||
|
(sum, op) => sum + JSON.stringify(op.toJSON()).length,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
getHash() {
|
getHash() {
|
||||||
if (this.operations.length) return null
|
if (this.operations.length) return null
|
||||||
|
|||||||
@@ -58,6 +58,27 @@ class StringFileData extends FileData {
|
|||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Record<string, number>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
// Note: Buffer does not exist in frontend. Use string length instead.
|
||||||
|
return {
|
||||||
|
nContent: 1,
|
||||||
|
contentSize: this.content.length,
|
||||||
|
nComments: this.comments.length,
|
||||||
|
commentsSize:
|
||||||
|
this.comments.length > 0
|
||||||
|
? JSON.stringify(this.comments.toRaw()).length
|
||||||
|
: 0,
|
||||||
|
nTrackedChanges: this.trackedChanges.length,
|
||||||
|
trackedChangesSize:
|
||||||
|
this.trackedChanges.length > 0
|
||||||
|
? JSON.stringify(this.trackedChanges.toRaw()).length
|
||||||
|
: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
isEditable() {
|
isEditable() {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -126,6 +126,18 @@ class FileMap {
|
|||||||
return _.mapValues(this.files, fileToRaw)
|
return _.mapValues(this.files, fileToRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Map<string, Record<string, number>>}
|
||||||
|
*/
|
||||||
|
toStats() {
|
||||||
|
const sizes = new Map()
|
||||||
|
for (const [path, file] of Object.entries(this.files)) {
|
||||||
|
if (!file) continue
|
||||||
|
sizes.set(path, file.toStats())
|
||||||
|
}
|
||||||
|
return sizes
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the given file.
|
* Create the given file.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ export class ProjectSnapshot {
|
|||||||
/**
|
/**
|
||||||
* Blob store that fetches blobs from the history service
|
* Blob store that fetches blobs from the history service
|
||||||
*/
|
*/
|
||||||
class SimpleBlobStore {
|
export class SimpleBlobStore {
|
||||||
private projectId: string
|
private projectId: string
|
||||||
|
|
||||||
constructor(projectId: string) {
|
constructor(projectId: string) {
|
||||||
@@ -280,7 +280,7 @@ async function flushHistory(projectId: string) {
|
|||||||
await postJSON(`/project/${projectId}/flush`)
|
await postJSON(`/project/${projectId}/flush`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchLatestChunk(projectId: string): Promise<Chunk> {
|
export async function fetchLatestChunk(projectId: string): Promise<Chunk> {
|
||||||
const response = await getJSON<{ chunk: RawChunk }>(
|
const response = await getJSON<{ chunk: RawChunk }>(
|
||||||
`/project/${projectId}/latest/history`
|
`/project/${projectId}/latest/history`
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user