From 9e712561913194f9c34482d298d1e879718f9c97 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Sat, 25 May 2024 06:15:07 -0400 Subject: [PATCH] chore(server): remove unused code (#9746) --- server/src/interfaces/library.interface.ts | 3 +- server/src/queries/library.repository.sql | 44 ------------------- server/src/queries/memory.repository.sql | 6 +++ server/src/repositories/asset.repository.ts | 2 +- server/src/repositories/library.repository.ts | 41 ++--------------- server/src/repositories/memory.repository.ts | 2 +- server/src/services/library.service.ts | 7 ++- .../repositories/library.repository.mock.ts | 1 - 8 files changed, 17 insertions(+), 89 deletions(-) diff --git a/server/src/interfaces/library.interface.ts b/server/src/interfaces/library.interface.ts index 30b8b39a0f..6468977df4 100644 --- a/server/src/interfaces/library.interface.ts +++ b/server/src/interfaces/library.interface.ts @@ -4,7 +4,6 @@ import { LibraryEntity } from 'src/entities/library.entity'; export const ILibraryRepository = 'ILibraryRepository'; export interface ILibraryRepository { - getCountForUser(ownerId: string): Promise; getAll(withDeleted?: boolean): Promise; getAllDeleted(): Promise; get(id: string, withDeleted?: boolean): Promise; @@ -12,6 +11,6 @@ export interface ILibraryRepository { delete(id: string): Promise; softDelete(id: string): Promise; update(library: Partial): Promise; - getStatistics(id: string): Promise; + getStatistics(id: string): Promise; getAssetIds(id: string, withDeleted?: boolean): Promise; } diff --git a/server/src/queries/library.repository.sql b/server/src/queries/library.repository.sql index b63bb35fd9..bc20bf4bd3 100644 --- a/server/src/queries/library.repository.sql +++ b/server/src/queries/library.repository.sql @@ -44,36 +44,6 @@ ORDER BY LIMIT 1 --- LibraryRepository.existsByName -SELECT - 1 AS "row_exists" -FROM - ( - SELECT - 1 AS dummy_column - ) "dummy_table" -WHERE - EXISTS ( - SELECT - 1 - FROM - "libraries" "LibraryEntity" - WHERE - ((("LibraryEntity"."name" = $1))) - AND ("LibraryEntity"."deletedAt" IS NULL) - ) -LIMIT - 1 - --- LibraryRepository.getCountForUser -SELECT - COUNT(1) AS "cnt" -FROM - "libraries" "LibraryEntity" -WHERE - ((("LibraryEntity"."ownerId" = $1))) - AND ("LibraryEntity"."deletedAt" IS NULL) - -- LibraryRepository.getAll SELECT "LibraryEntity"."id" AS "LibraryEntity_id", @@ -176,20 +146,6 @@ WHERE GROUP BY "libraries"."id" --- LibraryRepository.getOnlineAssetPaths -SELECT - "assets"."originalPath" AS "assets_originalPath" -FROM - "libraries" "library" - INNER JOIN "assets" "assets" ON "assets"."libraryId" = "library"."id" - AND ("assets"."deletedAt" IS NULL) -WHERE - ( - "library"."id" = $1 - AND "assets"."isOffline" = false - ) - AND ("library"."deletedAt" IS NULL) - -- LibraryRepository.getAssetIds SELECT "assets"."id" AS "assets_id" diff --git a/server/src/queries/memory.repository.sql b/server/src/queries/memory.repository.sql index aa3df240c1..691734e224 100644 --- a/server/src/queries/memory.repository.sql +++ b/server/src/queries/memory.repository.sql @@ -9,6 +9,12 @@ WHERE "memories_assets"."memoriesId" = $1 AND "memories_assets"."assetsId" IN ($2) +-- MemoryRepository.addAssetIds +INSERT INTO + "memories_assets_assets" ("memoriesId", "assetsId") +VALUES + ($1, $2) + -- MemoryRepository.removeAssetIds DELETE FROM "memories_assets_assets" WHERE diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts index ee8d9dbb93..356f78fee8 100644 --- a/server/src/repositories/asset.repository.ts +++ b/server/src/repositories/asset.repository.ts @@ -800,7 +800,7 @@ export class AssetRepository implements IAssetRepository { { ownerId: DummyValue.UUID, lastCreationDate: DummyValue.DATE, - lastId: DummyValue.STRING, + lastId: DummyValue.UUID, updatedUntil: DummyValue.DATE, limit: 10, }, diff --git a/server/src/repositories/library.repository.ts b/server/src/repositories/library.repository.ts index 30338315e8..963b0aaf73 100644 --- a/server/src/repositories/library.repository.ts +++ b/server/src/repositories/library.repository.ts @@ -5,7 +5,7 @@ import { LibraryStatsResponseDto } from 'src/dtos/library.dto'; import { LibraryEntity } from 'src/entities/library.entity'; import { ILibraryRepository } from 'src/interfaces/library.interface'; import { Instrumentation } from 'src/utils/instrumentation'; -import { EntityNotFoundError, IsNull, Not } from 'typeorm'; +import { IsNull, Not } from 'typeorm'; import { Repository } from 'typeorm/repository/Repository.js'; @Instrumentation() @@ -24,21 +24,6 @@ export class LibraryRepository implements ILibraryRepository { }); } - @GenerateSql({ params: [DummyValue.STRING] }) - existsByName(name: string, withDeleted = false): Promise { - return this.repository.exist({ - where: { - name, - }, - withDeleted, - }); - } - - @GenerateSql({ params: [DummyValue.UUID] }) - getCountForUser(ownerId: string): Promise { - return this.repository.countBy({ ownerId }); - } - @GenerateSql({ params: [] }) getAll(withDeleted = false): Promise { return this.repository.find({ @@ -85,7 +70,7 @@ export class LibraryRepository implements ILibraryRepository { } @GenerateSql({ params: [DummyValue.UUID] }) - async getStatistics(id: string): Promise { + async getStatistics(id: string): Promise { const stats = await this.repository .createQueryBuilder('libraries') .addSelect(`COUNT(assets.id) FILTER (WHERE assets.type = 'IMAGE' AND assets.isVisible)`, 'photos') @@ -98,7 +83,7 @@ export class LibraryRepository implements ILibraryRepository { .getRawOne(); if (!stats) { - throw new EntityNotFoundError(LibraryEntity, { where: { id } }); + return; } return { @@ -109,26 +94,6 @@ export class LibraryRepository implements ILibraryRepository { }; } - @GenerateSql({ params: [DummyValue.UUID] }) - async getOnlineAssetPaths(libraryId: string): Promise { - // Return all non-offline asset paths for a given library - const rawResults = await this.repository - .createQueryBuilder('library') - .innerJoinAndSelect('library.assets', 'assets') - .where('library.id = :id', { id: libraryId }) - .andWhere('assets.isOffline = false') - .select('assets.originalPath') - .getRawMany(); - - const results: string[] = []; - - for (const rawPath of rawResults) { - results.push(rawPath.assets_originalPath); - } - - return results; - } - @GenerateSql({ params: [DummyValue.UUID] }) async getAssetIds(libraryId: string, withDeleted = false): Promise { const builder = this.repository diff --git a/server/src/repositories/memory.repository.ts b/server/src/repositories/memory.repository.ts index 2a7997a0aa..a68d97152b 100644 --- a/server/src/repositories/memory.repository.ts +++ b/server/src/repositories/memory.repository.ts @@ -66,7 +66,7 @@ export class MemoryRepository implements IMemoryRepository { return new Set(results.map((row) => row['assetId'])); } - @GenerateSql({ params: [{ albumId: DummyValue.UUID, assetIds: [DummyValue.UUID] }] }) + @GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] }) async addAssetIds(id: string, assetIds: string[]): Promise { await this.dataSource .createQueryBuilder() diff --git a/server/src/services/library.service.ts b/server/src/services/library.service.ts index 3a87c418bd..9a01f2325f 100644 --- a/server/src/services/library.service.ts +++ b/server/src/services/library.service.ts @@ -215,8 +215,11 @@ export class LibraryService { } async getStatistics(id: string): Promise { - await this.findOrFail(id); - return this.repository.getStatistics(id); + const statistics = await this.repository.getStatistics(id); + if (!statistics) { + throw new BadRequestException('Library not found'); + } + return statistics; } async get(id: string): Promise { diff --git a/server/test/repositories/library.repository.mock.ts b/server/test/repositories/library.repository.mock.ts index 6f6100d933..e5b8e5c763 100644 --- a/server/test/repositories/library.repository.mock.ts +++ b/server/test/repositories/library.repository.mock.ts @@ -4,7 +4,6 @@ import { Mocked, vitest } from 'vitest'; export const newLibraryRepositoryMock = (): Mocked => { return { get: vitest.fn(), - getCountForUser: vitest.fn(), create: vitest.fn(), delete: vitest.fn(), softDelete: vitest.fn(),