mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-29 11:43:49 +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 {
|
export interface StorageAdapterEx extends StorageAdapter {
|
||||||
adapters?: Map<string, StorageAdapter>
|
adapters?: Map<string, StorageAdapter>
|
||||||
|
|
||||||
|
syncBlobFromStorage: (ctx: MeasureContext, workspaceId: WorkspaceId, objectName: string) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ad dummy storage adapter for tests
|
* Ad dummy storage adapter for tests
|
||||||
*/
|
*/
|
||||||
export class DummyStorageAdapter implements StorageAdapter, StorageAdapterEx {
|
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 initialize (ctx: MeasureContext, workspaceId: WorkspaceId): Promise<void> {}
|
||||||
|
|
||||||
async close (): Promise<void> {}
|
async close (): Promise<void> {}
|
||||||
|
@ -36,6 +36,28 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE
|
|||||||
readonly dbAdapter: RawDBAdapter
|
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> {
|
async initialize (ctx: MeasureContext, workspaceId: WorkspaceId): Promise<void> {
|
||||||
// We need to initialize internal table if it miss documents.
|
// We need to initialize internal table if it miss documents.
|
||||||
}
|
}
|
||||||
@ -219,7 +241,7 @@ export function buildStorage (
|
|||||||
config: StorageConfiguration,
|
config: StorageConfiguration,
|
||||||
dbAdapter: RawDBAdapter,
|
dbAdapter: RawDBAdapter,
|
||||||
storageFactory: (kind: string, config: StorageConfig) => StorageAdapter
|
storageFactory: (kind: string, config: StorageConfig) => StorageAdapter
|
||||||
): StorageAdapter {
|
): AggregatorStorageAdapter {
|
||||||
const adapters = new Map<string, StorageAdapter>()
|
const adapters = new Map<string, StorageAdapter>()
|
||||||
for (const c of config.storages) {
|
for (const c of config.storages) {
|
||||||
adapters.set(c.name, storageFactory(c.kind, c))
|
adapters.set(c.name, storageFactory(c.kind, c))
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import { MinioConfig, MinioService } from '@hcengineering/minio'
|
import { MinioConfig, MinioService } from '@hcengineering/minio'
|
||||||
import { createRawMongoDBAdapter } from '@hcengineering/mongo'
|
import { createRawMongoDBAdapter } from '@hcengineering/mongo'
|
||||||
import { S3Service, type S3Config } from '@hcengineering/s3'
|
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'
|
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 => {
|
return buildStorage(config, createRawMongoDBAdapter(dbUrl), (kind, config): StorageAdapter => {
|
||||||
if (kind === MinioService.config) {
|
if (kind === MinioService.config) {
|
||||||
const c = config as MinioConfig
|
const c = config as MinioConfig
|
||||||
|
Loading…
Reference in New Issue
Block a user