[web] extend history debugging with estimate on snapshot size (#32502)

GitOrigin-RevId: 6ee75d227c0d093e4698324f6cc018b077076730
This commit is contained in:
Jakob Ackermann
2026-03-30 08:03:17 +02:00
committed by Copybot
parent 9542334fef
commit 9f8f77e56f
10 changed files with 111 additions and 2 deletions

View File

@@ -123,6 +123,19 @@ class File {
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.
*

View File

@@ -33,6 +33,16 @@ class BinaryFileData extends FileData {
return new BinaryFileData(raw.hash, raw.byteLength)
}
/**
* @returns {Record<string, number>}
*/
toStats() {
return {
hashes: 1,
byteLength: this.byteLength,
}
}
/**
* @inheritdoc
* @returns {RawBinaryFileData}

View File

@@ -54,6 +54,15 @@ class HashFileData extends FileData {
return raw
}
/**
* @returns {Record<string, number>}
*/
toStats() {
return {
hashes: 1 + (this.rangesHash ? 1 : 0),
}
}
/**
* @inheritdoc
* @returns {string}

View File

@@ -36,6 +36,15 @@ class HollowBinaryFileData extends FileData {
return { byteLength: this.byteLength }
}
/**
* @returns {Record<string, number>}
*/
toStats() {
return {
byteLength: this.byteLength,
}
}
/** @inheritdoc */
getByteLength() {
return this.byteLength

View File

@@ -42,6 +42,15 @@ class HollowStringFileData extends FileData {
return { stringLength: this.stringLength }
}
/**
* @returns {Record<string, number>}
*/
toStats() {
return {
stringLength: this.stringLength,
}
}
/** @inheritdoc */
getStringLength() {
return this.stringLength

View File

@@ -81,6 +81,13 @@ class FileData {
throw new Error('FileData: toRaw not implemented')
}
/**
* @returns {Record<string, number>}
*/
toStats() {
throw new Error('FileData: toStats not implemented')
}
/**
* @see File#getHash
* @return {string | null | undefined}

View File

@@ -71,6 +71,25 @@ class LazyStringFileData extends FileData {
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 */
getHash() {
if (this.operations.length) return null

View File

@@ -58,6 +58,27 @@ class StringFileData extends FileData {
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 */
isEditable() {
return true

View File

@@ -126,6 +126,18 @@ class FileMap {
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.
*

View File

@@ -256,7 +256,7 @@ export class ProjectSnapshot {
/**
* Blob store that fetches blobs from the history service
*/
class SimpleBlobStore {
export class SimpleBlobStore {
private projectId: string
constructor(projectId: string) {
@@ -280,7 +280,7 @@ async function flushHistory(projectId: string) {
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 }>(
`/project/${projectId}/latest/history`
)