mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-25 18:02:04 +00:00
implement syncBlobFromStorage for AggregatorStorageAdapter (#5646)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
fe2756aabf
commit
f8eb0f5474
@ -60,12 +60,16 @@ export interface StorageAdapter {
|
||||
|
||||
export interface StorageAdapterEx extends StorageAdapter {
|
||||
adapters?: Map<string, StorageAdapter>
|
||||
|
||||
syncBlobFromStorage: (ctx: MeasureContext, workspaceId: WorkspaceId, objectName: string) => Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* Ad dummy storage adapter for tests
|
||||
*/
|
||||
export class DummyStorageAdapter implements StorageAdapter, StorageAdapterEx {
|
||||
async syncBlobFromStorage (ctx: MeasureContext, workspaceId: WorkspaceId, objectName: string): Promise<void> {}
|
||||
|
||||
async initialize (ctx: MeasureContext, workspaceId: WorkspaceId): Promise<void> {}
|
||||
|
||||
async close (): Promise<void> {}
|
||||
|
@ -36,6 +36,28 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE
|
||||
readonly dbAdapter: RawDBAdapter
|
||||
) {}
|
||||
|
||||
async syncBlobFromStorage (ctx: MeasureContext, workspaceId: WorkspaceId, objectName: string): Promise<void> {
|
||||
const current = await this.dbAdapter.find<Blob>(
|
||||
ctx,
|
||||
workspaceId,
|
||||
DOMAIN_BLOB,
|
||||
{ _class: core.class.Blob, _id: objectName as Ref<Blob> },
|
||||
{ limit: 1 }
|
||||
)
|
||||
const provider = this.adapters.get(current[0]?.provider ?? this.defaultAdapter)
|
||||
if (provider === undefined) {
|
||||
throw new NoSuchKeyError('No such provider found')
|
||||
}
|
||||
const stat = await provider.stat(ctx, workspaceId, objectName)
|
||||
if (stat !== undefined) {
|
||||
stat.provider = current[0]?.provider ?? this.defaultAdapter
|
||||
if (current[0] !== undefined) {
|
||||
await this.dbAdapter.clean(ctx, workspaceId, DOMAIN_BLOB, [current[0]._id])
|
||||
}
|
||||
await this.dbAdapter.upload<Blob>(ctx, workspaceId, DOMAIN_BLOB, [stat])
|
||||
}
|
||||
}
|
||||
|
||||
async initialize (ctx: MeasureContext, workspaceId: WorkspaceId): Promise<void> {
|
||||
// We need to initialize internal table if it miss documents.
|
||||
}
|
||||
@ -219,7 +241,7 @@ export function buildStorage (
|
||||
config: StorageConfiguration,
|
||||
dbAdapter: RawDBAdapter,
|
||||
storageFactory: (kind: string, config: StorageConfig) => StorageAdapter
|
||||
): StorageAdapter {
|
||||
): AggregatorStorageAdapter {
|
||||
const adapters = new Map<string, StorageAdapter>()
|
||||
for (const c of config.storages) {
|
||||
adapters.set(c.name, storageFactory(c.kind, c))
|
||||
|
@ -1,7 +1,13 @@
|
||||
import { MinioConfig, MinioService } from '@hcengineering/minio'
|
||||
import { createRawMongoDBAdapter } from '@hcengineering/mongo'
|
||||
import { S3Service, type S3Config } from '@hcengineering/s3'
|
||||
import { StorageAdapter, StorageConfiguration, buildStorage, type StorageConfig } from '@hcengineering/server-core'
|
||||
import {
|
||||
AggregatorStorageAdapter,
|
||||
StorageAdapter,
|
||||
StorageConfiguration,
|
||||
buildStorage,
|
||||
type StorageConfig
|
||||
} from '@hcengineering/server-core'
|
||||
import { addMinioFallback } from './minio'
|
||||
|
||||
/*
|
||||
@ -71,7 +77,7 @@ export function parseStorageEnv (storageEnv: string, storageConfig: StorageConfi
|
||||
}
|
||||
}
|
||||
|
||||
export function buildStorageFromConfig (config: StorageConfiguration, dbUrl: string): StorageAdapter {
|
||||
export function buildStorageFromConfig (config: StorageConfiguration, dbUrl: string): AggregatorStorageAdapter {
|
||||
return buildStorage(config, createRawMongoDBAdapter(dbUrl), (kind, config): StorageAdapter => {
|
||||
if (kind === MinioService.config) {
|
||||
const c = config as MinioConfig
|
||||
|
Loading…
Reference in New Issue
Block a user