fix comments

This commit is contained in:
Jonathan Jogenfors
2026-02-25 00:39:58 +01:00
parent 016c338877
commit c65bc8762f
14 changed files with 336 additions and 227 deletions

View File

@@ -136,9 +136,6 @@ export class LibraryStatsResponseDto {
@ApiProperty({ type: 'integer', description: 'Total number of assets' })
total = 0;
@ApiProperty({ type: 'integer', description: 'Number of offline assets' })
offline = 0;
@ApiProperty({ type: 'integer', format: 'int64', description: 'Storage usage in bytes' })
usage = 0;
}

View File

@@ -36,37 +36,27 @@ select
(
"asset"."type" = $1
and "asset"."visibility" != $2
and "asset"."isOffline" = $3
)
) as "photos",
count(*) filter (
where
(
"asset"."type" = $4
and "asset"."visibility" != $5
and "asset"."isOffline" = $6
"asset"."type" = $3
and "asset"."visibility" != $4
)
) as "videos",
count(*) filter (
where
(
"asset"."isOffline" = $7
and "asset"."visibility" != $8
)
) as "offline",
coalesce(sum("asset_exif"."fileSizeInByte"), $9) as "usage"
coalesce(sum("asset_exif"."fileSizeInByte"), $5) as "usage"
from
"library"
inner join "asset" on "asset"."libraryId" = "library"."id"
left join "asset_exif" on "asset_exif"."assetId" = "asset"."id"
where
"library"."id" = $10
"library"."id" = $6
group by
"library"."id"
select
0::int as "photos",
0::int as "videos",
0::int as "offline",
0::int as "usage",
0::int as "total"
from

View File

@@ -79,11 +79,7 @@ export class LibraryRepository {
eb.fn
.countAll<number>()
.filterWhere((eb) =>
eb.and([
eb('asset.type', '=', AssetType.Image),
eb('asset.visibility', '!=', AssetVisibility.Hidden),
eb('asset.isOffline', '=', false),
]),
eb.and([eb('asset.type', '=', AssetType.Image), eb('asset.visibility', '!=', AssetVisibility.Hidden)]),
)
.as('photos'),
)
@@ -91,22 +87,10 @@ export class LibraryRepository {
eb.fn
.countAll<number>()
.filterWhere((eb) =>
eb.and([
eb('asset.type', '=', AssetType.Video),
eb('asset.visibility', '!=', AssetVisibility.Hidden),
eb('asset.isOffline', '=', false),
]),
eb.and([eb('asset.type', '=', AssetType.Video), eb('asset.visibility', '!=', AssetVisibility.Hidden)]),
)
.as('videos'),
)
.select((eb) =>
eb.fn
.countAll<number>()
.filterWhere((eb) =>
eb.and([eb('asset.isOffline', '=', true), eb('asset.visibility', '!=', AssetVisibility.Hidden)]),
)
.as('offline'),
)
.select((eb) => eb.fn.coalesce((eb) => eb.fn.sum('asset_exif.fileSizeInByte'), eb.val(0)).as('usage'))
.groupBy('library.id')
.where('library.id', '=', id)
@@ -119,7 +103,6 @@ export class LibraryRepository {
.selectFrom('library')
.select(zero.as('photos'))
.select(zero.as('videos'))
.select(zero.as('offline'))
.select(zero.as('usage'))
.select(zero.as('total'))
.where('library.id', '=', id)
@@ -129,7 +112,6 @@ export class LibraryRepository {
return {
photos: stats.photos,
videos: stats.videos,
offline: stats.offline,
usage: stats.usage,
total: stats.photos + stats.videos,
};

View File

@@ -681,19 +681,12 @@ describe(LibraryService.name, () => {
it('should return library statistics', async () => {
const library = factory.library();
mocks.library.getStatistics.mockResolvedValue({
photos: 10,
videos: 0,
total: 10,
usage: 1337,
offline: 67,
});
mocks.library.getStatistics.mockResolvedValue({ photos: 10, videos: 0, total: 10, usage: 1337 });
await expect(sut.getStatistics(library.id)).resolves.toEqual({
photos: 10,
videos: 0,
total: 10,
usage: 1337,
offline: 67,
});
expect(mocks.library.getStatistics).toHaveBeenCalledWith(library.id);