Skip to content

Commit b5c82bc

Browse files
authored
Reduce stat calls from sync blob (#6890)
Signed-off-by: Denis Bykhov <[email protected]>
1 parent 00d8cf2 commit b5c82bc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/server-storage/src/aggregator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,23 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE
5555
let current: Blob | undefined = (
5656
await this.dbAdapter.find<Blob>(ctx, workspaceId, DOMAIN_BLOB, { _id: objectName as Ref<Blob> }, { limit: 1 })
5757
).shift()
58+
let updated = false
5859
if (current === undefined && providerId !== undefined) {
5960
current = await this.adapters.get(providerId)?.stat(ctx, workspaceId, objectName)
6061
if (current !== undefined) {
6162
current.provider = providerId
63+
updated = true
6264
}
6365
}
6466

6567
const provider = this.adapters.get(providerId ?? current?.provider ?? this.defaultAdapter)
6668
if (provider === undefined) {
6769
throw new NoSuchKeyError('No such provider found')
6870
}
69-
const stat = await provider.stat(ctx, workspaceId, objectName)
71+
const stat = updated ? current : await provider.stat(ctx, workspaceId, objectName)
7072
if (stat !== undefined) {
7173
stat.provider = providerId ?? current?.provider ?? this.defaultAdapter
72-
if (current !== undefined) {
74+
if (current !== undefined && !updated) {
7375
await this.dbAdapter.clean(ctx, workspaceId, DOMAIN_BLOB, [current._id])
7476
}
7577
await this.dbAdapter.upload<Blob>(ctx, workspaceId, DOMAIN_BLOB, [stat])

0 commit comments

Comments
 (0)