Skip to content

Commit

Permalink
Reduce stat calls from sync blob (#6890)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Bykhov <[email protected]>
  • Loading branch information
BykhovDenis authored Oct 11, 2024
1 parent 00d8cf2 commit b5c82bc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/server-storage/src/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,23 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE
let current: Blob | undefined = (
await this.dbAdapter.find<Blob>(ctx, workspaceId, DOMAIN_BLOB, { _id: objectName as Ref<Blob> }, { 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
}
}

const provider = this.adapters.get(providerId ?? current?.provider ?? this.defaultAdapter)
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<Blob>(ctx, workspaceId, DOMAIN_BLOB, [stat])
Expand Down

0 comments on commit b5c82bc

Please sign in to comment.