mirror of
https://github.com/immich-app/immich.git
synced 2026-03-01 18:19:10 +03:00
refactor: migrate memory repository (#15532)
This commit is contained in:
@@ -11,7 +11,6 @@ import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { IMachineLearningRepository } from 'src/interfaces/machine-learning.interface';
|
||||
import { IMapRepository } from 'src/interfaces/map.interface';
|
||||
import { IMediaRepository } from 'src/interfaces/media.interface';
|
||||
import { IMemoryRepository } from 'src/interfaces/memory.interface';
|
||||
import { IMetadataRepository } from 'src/interfaces/metadata.interface';
|
||||
import { IMoveRepository } from 'src/interfaces/move.interface';
|
||||
import { INotificationRepository } from 'src/interfaces/notification.interface';
|
||||
@@ -78,6 +77,7 @@ export const repositories = [
|
||||
AuditRepository,
|
||||
ApiKeyRepository,
|
||||
ConfigRepository,
|
||||
MemoryRepository,
|
||||
ViewRepository,
|
||||
];
|
||||
|
||||
@@ -95,7 +95,6 @@ export const providers = [
|
||||
{ provide: IMachineLearningRepository, useClass: MachineLearningRepository },
|
||||
{ provide: IMapRepository, useClass: MapRepository },
|
||||
{ provide: IMediaRepository, useClass: MediaRepository },
|
||||
{ provide: IMemoryRepository, useClass: MemoryRepository },
|
||||
{ provide: IMetadataRepository, useClass: MetadataRepository },
|
||||
{ provide: IMoveRepository, useClass: MoveRepository },
|
||||
{ provide: INotificationRepository, useClass: NotificationRepository },
|
||||
|
||||
@@ -4,29 +4,28 @@ import { jsonArrayFrom } from 'kysely/helpers/postgres';
|
||||
import { InjectKysely } from 'nestjs-kysely';
|
||||
import { DB, Memories } from 'src/db';
|
||||
import { Chunked, ChunkedSet, DummyValue, GenerateSql } from 'src/decorators';
|
||||
import { MemoryEntity } from 'src/entities/memory.entity';
|
||||
import { IMemoryRepository } from 'src/interfaces/memory.interface';
|
||||
import { IBulkAsset } from 'src/utils/asset.util';
|
||||
|
||||
@Injectable()
|
||||
export class MemoryRepository implements IMemoryRepository {
|
||||
export class MemoryRepository implements IBulkAsset {
|
||||
constructor(@InjectKysely() private db: Kysely<DB>) {}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
search(ownerId: string): Promise<MemoryEntity[]> {
|
||||
search(ownerId: string) {
|
||||
return this.db
|
||||
.selectFrom('memories')
|
||||
.selectAll()
|
||||
.where('ownerId', '=', ownerId)
|
||||
.orderBy('memoryAt', 'desc')
|
||||
.execute() as Promise<MemoryEntity[]>;
|
||||
.execute();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
get(id: string): Promise<MemoryEntity | undefined> {
|
||||
return this.getByIdBuilder(id).executeTakeFirst() as unknown as Promise<MemoryEntity | undefined>;
|
||||
get(id: string) {
|
||||
return this.getByIdBuilder(id).executeTakeFirst();
|
||||
}
|
||||
|
||||
async create(memory: Insertable<Memories>, assetIds: Set<string>): Promise<MemoryEntity> {
|
||||
async create(memory: Insertable<Memories>, assetIds: Set<string>) {
|
||||
const id = await this.db.transaction().execute(async (tx) => {
|
||||
const { id } = await tx.insertInto('memories').values(memory).returning('id').executeTakeFirstOrThrow();
|
||||
|
||||
@@ -38,25 +37,25 @@ export class MemoryRepository implements IMemoryRepository {
|
||||
return id;
|
||||
});
|
||||
|
||||
return this.getByIdBuilder(id).executeTakeFirstOrThrow() as unknown as Promise<MemoryEntity>;
|
||||
return this.getByIdBuilder(id).executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID, { ownerId: DummyValue.UUID, isSaved: true }] })
|
||||
async update(id: string, memory: Updateable<Memories>): Promise<MemoryEntity> {
|
||||
async update(id: string, memory: Updateable<Memories>) {
|
||||
await this.db.updateTable('memories').set(memory).where('id', '=', id).execute();
|
||||
return this.getByIdBuilder(id).executeTakeFirstOrThrow() as unknown as Promise<MemoryEntity>;
|
||||
return this.getByIdBuilder(id).executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
async delete(id: string): Promise<void> {
|
||||
async delete(id: string) {
|
||||
await this.db.deleteFrom('memories').where('id', '=', id).execute();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] })
|
||||
@ChunkedSet({ paramIndex: 1 })
|
||||
async getAssetIds(id: string, assetIds: string[]): Promise<Set<string>> {
|
||||
async getAssetIds(id: string, assetIds: string[]) {
|
||||
if (assetIds.length === 0) {
|
||||
return new Set();
|
||||
return new Set<string>();
|
||||
}
|
||||
|
||||
const results = await this.db
|
||||
@@ -70,7 +69,7 @@ export class MemoryRepository implements IMemoryRepository {
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] })
|
||||
async addAssetIds(id: string, assetIds: string[]): Promise<void> {
|
||||
async addAssetIds(id: string, assetIds: string[]) {
|
||||
if (assetIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -83,7 +82,7 @@ export class MemoryRepository implements IMemoryRepository {
|
||||
|
||||
@Chunked({ paramIndex: 1 })
|
||||
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] })
|
||||
async removeAssetIds(id: string, assetIds: string[]): Promise<void> {
|
||||
async removeAssetIds(id: string, assetIds: string[]) {
|
||||
if (assetIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user