mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-30 15:42:49 +03:00
chore(server): cache blob list result (#6297)
This commit is contained in:
parent
0731872347
commit
b8e6d7d6cb
@ -1,13 +1,13 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
import type {
|
||||
BlobInputType,
|
||||
EventPayload,
|
||||
StorageProvider,
|
||||
} from '../../../fundamentals';
|
||||
import {
|
||||
BlobInputType,
|
||||
Cache,
|
||||
EventEmitter,
|
||||
type EventPayload,
|
||||
ListObjectsMetadata,
|
||||
OnEvent,
|
||||
StorageProvider,
|
||||
StorageProviderFactory,
|
||||
} from '../../../fundamentals';
|
||||
|
||||
@ -17,13 +17,15 @@ export class WorkspaceBlobStorage {
|
||||
|
||||
constructor(
|
||||
private readonly event: EventEmitter,
|
||||
private readonly storageFactory: StorageProviderFactory
|
||||
private readonly storageFactory: StorageProviderFactory,
|
||||
@Inject(forwardRef(() => Cache)) private readonly cache: Cache
|
||||
) {
|
||||
this.provider = this.storageFactory.create('blob');
|
||||
}
|
||||
|
||||
async put(workspaceId: string, key: string, blob: BlobInputType) {
|
||||
await this.provider.put(`${workspaceId}/${key}`, blob);
|
||||
await this.cache.delete(`blobs:${workspaceId}`);
|
||||
}
|
||||
|
||||
async get(workspaceId: string, key: string) {
|
||||
@ -31,6 +33,16 @@ export class WorkspaceBlobStorage {
|
||||
}
|
||||
|
||||
async list(workspaceId: string) {
|
||||
const cachedList = await this.cache.list<ListObjectsMetadata>(
|
||||
`blobs:${workspaceId}`,
|
||||
0,
|
||||
-1
|
||||
);
|
||||
|
||||
if (cachedList.length > 0) {
|
||||
return cachedList;
|
||||
}
|
||||
|
||||
const blobs = await this.provider.list(workspaceId + '/');
|
||||
|
||||
blobs.forEach(item => {
|
||||
@ -38,6 +50,8 @@ export class WorkspaceBlobStorage {
|
||||
item.key = item.key.slice(workspaceId.length + 1);
|
||||
});
|
||||
|
||||
await this.cache.pushBack(`blobs:${workspaceId}`, ...blobs);
|
||||
|
||||
return blobs;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user