mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-25 11:05:07 +02:00
UBERF-8578: Fix extra stat call for storage adapter (#7132)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -28,17 +28,20 @@ export async function yDocFromStorage (
|
||||
ydoc?: YDoc
|
||||
): Promise<YDoc | undefined> {
|
||||
// stat the object to ensure it exists, because read will throw an error in this case
|
||||
const blob = await storageAdapter.stat(ctx, workspace, documentId)
|
||||
if (blob === undefined) {
|
||||
return undefined
|
||||
try {
|
||||
const buffer = await storageAdapter.read(ctx, workspace, documentId)
|
||||
|
||||
// no need to apply gc because we load existing document
|
||||
// it is either already gc-ed, or gc not needed and it is disabled
|
||||
ydoc ??= new YDoc({ guid: generateId(), gc: false })
|
||||
|
||||
return yDocFromBuffer(Buffer.concat(buffer as any), ydoc)
|
||||
} catch (err: any) {
|
||||
if (err.code === 'NoSuchKey') {
|
||||
return undefined
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
// no need to apply gc because we load existing document
|
||||
// it is either already gc-ed, or gc not needed and it is disabled
|
||||
ydoc ??= new YDoc({ guid: generateId(), gc: false })
|
||||
|
||||
const buffer = await storageAdapter.read(ctx, workspace, documentId)
|
||||
return yDocFromBuffer(Buffer.concat(buffer as any), ydoc)
|
||||
}
|
||||
|
||||
/** @public */
|
||||
|
||||
Reference in New Issue
Block a user