mirror of
https://github.com/immich-app/immich.git
synced 2025-06-01 04:36:19 -04:00
chore(server): remove unused code (#9746)
This commit is contained in:
parent
d5cf8e4bfe
commit
9e71256191
@ -4,7 +4,6 @@ import { LibraryEntity } from 'src/entities/library.entity';
|
|||||||
export const ILibraryRepository = 'ILibraryRepository';
|
export const ILibraryRepository = 'ILibraryRepository';
|
||||||
|
|
||||||
export interface ILibraryRepository {
|
export interface ILibraryRepository {
|
||||||
getCountForUser(ownerId: string): Promise<number>;
|
|
||||||
getAll(withDeleted?: boolean): Promise<LibraryEntity[]>;
|
getAll(withDeleted?: boolean): Promise<LibraryEntity[]>;
|
||||||
getAllDeleted(): Promise<LibraryEntity[]>;
|
getAllDeleted(): Promise<LibraryEntity[]>;
|
||||||
get(id: string, withDeleted?: boolean): Promise<LibraryEntity | null>;
|
get(id: string, withDeleted?: boolean): Promise<LibraryEntity | null>;
|
||||||
@ -12,6 +11,6 @@ export interface ILibraryRepository {
|
|||||||
delete(id: string): Promise<void>;
|
delete(id: string): Promise<void>;
|
||||||
softDelete(id: string): Promise<void>;
|
softDelete(id: string): Promise<void>;
|
||||||
update(library: Partial<LibraryEntity>): Promise<LibraryEntity>;
|
update(library: Partial<LibraryEntity>): Promise<LibraryEntity>;
|
||||||
getStatistics(id: string): Promise<LibraryStatsResponseDto>;
|
getStatistics(id: string): Promise<LibraryStatsResponseDto | undefined>;
|
||||||
getAssetIds(id: string, withDeleted?: boolean): Promise<string[]>;
|
getAssetIds(id: string, withDeleted?: boolean): Promise<string[]>;
|
||||||
}
|
}
|
||||||
|
@ -44,36 +44,6 @@ ORDER BY
|
|||||||
LIMIT
|
LIMIT
|
||||||
1
|
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
|
-- LibraryRepository.getAll
|
||||||
SELECT
|
SELECT
|
||||||
"LibraryEntity"."id" AS "LibraryEntity_id",
|
"LibraryEntity"."id" AS "LibraryEntity_id",
|
||||||
@ -176,20 +146,6 @@ WHERE
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
"libraries"."id"
|
"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
|
-- LibraryRepository.getAssetIds
|
||||||
SELECT
|
SELECT
|
||||||
"assets"."id" AS "assets_id"
|
"assets"."id" AS "assets_id"
|
||||||
|
@ -9,6 +9,12 @@ WHERE
|
|||||||
"memories_assets"."memoriesId" = $1
|
"memories_assets"."memoriesId" = $1
|
||||||
AND "memories_assets"."assetsId" IN ($2)
|
AND "memories_assets"."assetsId" IN ($2)
|
||||||
|
|
||||||
|
-- MemoryRepository.addAssetIds
|
||||||
|
INSERT INTO
|
||||||
|
"memories_assets_assets" ("memoriesId", "assetsId")
|
||||||
|
VALUES
|
||||||
|
($1, $2)
|
||||||
|
|
||||||
-- MemoryRepository.removeAssetIds
|
-- MemoryRepository.removeAssetIds
|
||||||
DELETE FROM "memories_assets_assets"
|
DELETE FROM "memories_assets_assets"
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -800,7 +800,7 @@ export class AssetRepository implements IAssetRepository {
|
|||||||
{
|
{
|
||||||
ownerId: DummyValue.UUID,
|
ownerId: DummyValue.UUID,
|
||||||
lastCreationDate: DummyValue.DATE,
|
lastCreationDate: DummyValue.DATE,
|
||||||
lastId: DummyValue.STRING,
|
lastId: DummyValue.UUID,
|
||||||
updatedUntil: DummyValue.DATE,
|
updatedUntil: DummyValue.DATE,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
},
|
},
|
||||||
|
@ -5,7 +5,7 @@ import { LibraryStatsResponseDto } from 'src/dtos/library.dto';
|
|||||||
import { LibraryEntity } from 'src/entities/library.entity';
|
import { LibraryEntity } from 'src/entities/library.entity';
|
||||||
import { ILibraryRepository } from 'src/interfaces/library.interface';
|
import { ILibraryRepository } from 'src/interfaces/library.interface';
|
||||||
import { Instrumentation } from 'src/utils/instrumentation';
|
import { Instrumentation } from 'src/utils/instrumentation';
|
||||||
import { EntityNotFoundError, IsNull, Not } from 'typeorm';
|
import { IsNull, Not } from 'typeorm';
|
||||||
import { Repository } from 'typeorm/repository/Repository.js';
|
import { Repository } from 'typeorm/repository/Repository.js';
|
||||||
|
|
||||||
@Instrumentation()
|
@Instrumentation()
|
||||||
@ -24,21 +24,6 @@ export class LibraryRepository implements ILibraryRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.STRING] })
|
|
||||||
existsByName(name: string, withDeleted = false): Promise<boolean> {
|
|
||||||
return this.repository.exist({
|
|
||||||
where: {
|
|
||||||
name,
|
|
||||||
},
|
|
||||||
withDeleted,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID] })
|
|
||||||
getCountForUser(ownerId: string): Promise<number> {
|
|
||||||
return this.repository.countBy({ ownerId });
|
|
||||||
}
|
|
||||||
|
|
||||||
@GenerateSql({ params: [] })
|
@GenerateSql({ params: [] })
|
||||||
getAll(withDeleted = false): Promise<LibraryEntity[]> {
|
getAll(withDeleted = false): Promise<LibraryEntity[]> {
|
||||||
return this.repository.find({
|
return this.repository.find({
|
||||||
@ -85,7 +70,7 @@ export class LibraryRepository implements ILibraryRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID] })
|
@GenerateSql({ params: [DummyValue.UUID] })
|
||||||
async getStatistics(id: string): Promise<LibraryStatsResponseDto> {
|
async getStatistics(id: string): Promise<LibraryStatsResponseDto | undefined> {
|
||||||
const stats = await this.repository
|
const stats = await this.repository
|
||||||
.createQueryBuilder('libraries')
|
.createQueryBuilder('libraries')
|
||||||
.addSelect(`COUNT(assets.id) FILTER (WHERE assets.type = 'IMAGE' AND assets.isVisible)`, 'photos')
|
.addSelect(`COUNT(assets.id) FILTER (WHERE assets.type = 'IMAGE' AND assets.isVisible)`, 'photos')
|
||||||
@ -98,7 +83,7 @@ export class LibraryRepository implements ILibraryRepository {
|
|||||||
.getRawOne();
|
.getRawOne();
|
||||||
|
|
||||||
if (!stats) {
|
if (!stats) {
|
||||||
throw new EntityNotFoundError(LibraryEntity, { where: { id } });
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -109,26 +94,6 @@ export class LibraryRepository implements ILibraryRepository {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID] })
|
|
||||||
async getOnlineAssetPaths(libraryId: string): Promise<string[]> {
|
|
||||||
// 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] })
|
@GenerateSql({ params: [DummyValue.UUID] })
|
||||||
async getAssetIds(libraryId: string, withDeleted = false): Promise<string[]> {
|
async getAssetIds(libraryId: string, withDeleted = false): Promise<string[]> {
|
||||||
const builder = this.repository
|
const builder = this.repository
|
||||||
|
@ -66,7 +66,7 @@ export class MemoryRepository implements IMemoryRepository {
|
|||||||
return new Set(results.map((row) => row['assetId']));
|
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<void> {
|
async addAssetIds(id: string, assetIds: string[]): Promise<void> {
|
||||||
await this.dataSource
|
await this.dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
|
@ -215,8 +215,11 @@ export class LibraryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getStatistics(id: string): Promise<LibraryStatsResponseDto> {
|
async getStatistics(id: string): Promise<LibraryStatsResponseDto> {
|
||||||
await this.findOrFail(id);
|
const statistics = await this.repository.getStatistics(id);
|
||||||
return this.repository.getStatistics(id);
|
if (!statistics) {
|
||||||
|
throw new BadRequestException('Library not found');
|
||||||
|
}
|
||||||
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(id: string): Promise<LibraryResponseDto> {
|
async get(id: string): Promise<LibraryResponseDto> {
|
||||||
|
@ -4,7 +4,6 @@ import { Mocked, vitest } from 'vitest';
|
|||||||
export const newLibraryRepositoryMock = (): Mocked<ILibraryRepository> => {
|
export const newLibraryRepositoryMock = (): Mocked<ILibraryRepository> => {
|
||||||
return {
|
return {
|
||||||
get: vitest.fn(),
|
get: vitest.fn(),
|
||||||
getCountForUser: vitest.fn(),
|
|
||||||
create: vitest.fn(),
|
create: vitest.fn(),
|
||||||
delete: vitest.fn(),
|
delete: vitest.fn(),
|
||||||
softDelete: vitest.fn(),
|
softDelete: vitest.fn(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user