From 15aab676204c2dc76487e4bb5ed688c10c2042c3 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Fri, 11 Oct 2024 23:55:29 +0500 Subject: [PATCH] Reduce stat calls from sync blob (#6890) Signed-off-by: Denis Bykhov --- server/server-storage/src/aggregator.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/server-storage/src/aggregator.ts b/server/server-storage/src/aggregator.ts index db02d98b84f..d10bfcbb1d5 100644 --- a/server/server-storage/src/aggregator.ts +++ b/server/server-storage/src/aggregator.ts @@ -55,10 +55,12 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE let current: Blob | undefined = ( await this.dbAdapter.find(ctx, workspaceId, DOMAIN_BLOB, { _id: objectName as Ref }, { limit: 1 }) ).shift() + let updated = false if (current === undefined && providerId !== undefined) { current = await this.adapters.get(providerId)?.stat(ctx, workspaceId, objectName) if (current !== undefined) { current.provider = providerId + updated = true } } @@ -66,10 +68,10 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE if (provider === undefined) { throw new NoSuchKeyError('No such provider found') } - const stat = await provider.stat(ctx, workspaceId, objectName) + const stat = updated ? current : await provider.stat(ctx, workspaceId, objectName) if (stat !== undefined) { stat.provider = providerId ?? current?.provider ?? this.defaultAdapter - if (current !== undefined) { + if (current !== undefined && !updated) { await this.dbAdapter.clean(ctx, workspaceId, DOMAIN_BLOB, [current._id]) } await this.dbAdapter.upload(ctx, workspaceId, DOMAIN_BLOB, [stat])