mirror of
https://github.com/immich-app/immich.git
synced 2026-03-22 22:19:51 +03:00
feat: add offline library statistics
This commit is contained in:
@@ -136,6 +136,9 @@ 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;
|
||||
}
|
||||
|
||||
@@ -36,27 +36,37 @@ select
|
||||
(
|
||||
"asset"."type" = $1
|
||||
and "asset"."visibility" != $2
|
||||
and "asset"."isOffline" = $3
|
||||
)
|
||||
) as "photos",
|
||||
count(*) filter (
|
||||
where
|
||||
(
|
||||
"asset"."type" = $3
|
||||
and "asset"."visibility" != $4
|
||||
"asset"."type" = $4
|
||||
and "asset"."visibility" != $5
|
||||
and "asset"."isOffline" = $6
|
||||
)
|
||||
) as "videos",
|
||||
coalesce(sum("asset_exif"."fileSizeInByte"), $5) as "usage"
|
||||
count(*) filter (
|
||||
where
|
||||
(
|
||||
"asset"."isOffline" = $7
|
||||
and "asset"."visibility" != $8
|
||||
)
|
||||
) as "offline",
|
||||
coalesce(sum("asset_exif"."fileSizeInByte"), $9) 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" = $6
|
||||
"library"."id" = $10
|
||||
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
|
||||
|
||||
@@ -79,7 +79,11 @@ export class LibraryRepository {
|
||||
eb.fn
|
||||
.countAll<number>()
|
||||
.filterWhere((eb) =>
|
||||
eb.and([eb('asset.type', '=', AssetType.Image), eb('asset.visibility', '!=', AssetVisibility.Hidden)]),
|
||||
eb.and([
|
||||
eb('asset.type', '=', AssetType.Image),
|
||||
eb('asset.visibility', '!=', AssetVisibility.Hidden),
|
||||
eb('asset.isOffline', '=', false),
|
||||
]),
|
||||
)
|
||||
.as('photos'),
|
||||
)
|
||||
@@ -87,10 +91,22 @@ export class LibraryRepository {
|
||||
eb.fn
|
||||
.countAll<number>()
|
||||
.filterWhere((eb) =>
|
||||
eb.and([eb('asset.type', '=', AssetType.Video), eb('asset.visibility', '!=', AssetVisibility.Hidden)]),
|
||||
eb.and([
|
||||
eb('asset.type', '=', AssetType.Video),
|
||||
eb('asset.visibility', '!=', AssetVisibility.Hidden),
|
||||
eb('asset.isOffline', '=', false),
|
||||
]),
|
||||
)
|
||||
.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)
|
||||
@@ -103,6 +119,7 @@ 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)
|
||||
@@ -112,6 +129,7 @@ export class LibraryRepository {
|
||||
return {
|
||||
photos: stats.photos,
|
||||
videos: stats.videos,
|
||||
offline: stats.offline,
|
||||
usage: stats.usage,
|
||||
total: stats.photos + stats.videos,
|
||||
};
|
||||
|
||||
@@ -681,12 +681,19 @@ 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 });
|
||||
mocks.library.getStatistics.mockResolvedValue({
|
||||
photos: 10,
|
||||
videos: 0,
|
||||
total: 10,
|
||||
usage: 1337,
|
||||
offline: 67,
|
||||
});
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user