From f5c4af73aa0d7739fc1121d4dc4d01083eea6a24 Mon Sep 17 00:00:00 2001 From: weathondev Date: Fri, 15 Nov 2024 23:38:57 +0100 Subject: [PATCH] feat: adding photo & video storage space to server stats (#14125) * expose detailed user storage stats + display them in the storage per user table * chore: openapi & sql * fix: fix test stubs * fix: formatting errors, e2e test and server test * fix: upper lower case typo in spec file --------- Co-authored-by: Alex Tran --- e2e/src/api/specs/server.e2e-spec.ts | 6 ++++ .../lib/model/server_stats_response_dto.dart | Bin 3670 -> 4214 bytes .../openapi/lib/model/usage_by_user_dto.dart | Bin 4151 -> 4705 bytes open-api/immich-openapi-specs.json | 26 +++++++++++++++++- open-api/typescript-sdk/src/fetch-client.ts | 4 +++ server/src/dtos/server.dto.ts | 14 +++++++++- server/src/interfaces/user.interface.ts | 2 ++ server/src/queries/user.repository.sql | 18 +++++++++++- server/src/repositories/user.repository.ts | 10 +++++++ server/src/services/server.service.spec.ts | 14 ++++++++++ server/src/services/server.service.ts | 5 ++++ .../server-stats/server-stats-panel.svelte | 10 +++++-- 12 files changed, 104 insertions(+), 5 deletions(-) diff --git a/e2e/src/api/specs/server.e2e-spec.ts b/e2e/src/api/specs/server.e2e-spec.ts index 3133460ada..4bff4b3dea 100644 --- a/e2e/src/api/specs/server.e2e-spec.ts +++ b/e2e/src/api/specs/server.e2e-spec.ts @@ -163,11 +163,15 @@ describe('/server', () => { expect(body).toEqual({ photos: 0, usage: 0, + usagePhotos: 0, + usageVideos: 0, usageByUser: [ { quotaSizeInBytes: null, photos: 0, usage: 0, + usagePhotos: 0, + usageVideos: 0, userName: 'Immich Admin', userId: admin.userId, videos: 0, @@ -176,6 +180,8 @@ describe('/server', () => { quotaSizeInBytes: null, photos: 0, usage: 0, + usagePhotos: 0, + usageVideos: 0, userName: 'User 1', userId: nonAdmin.userId, videos: 0, diff --git a/mobile/openapi/lib/model/server_stats_response_dto.dart b/mobile/openapi/lib/model/server_stats_response_dto.dart index 654a34ee6b0e77082d981ad6447040fb8fbbd11d..531fa8f03e16a0760ffb83f586e70961682b9948 100644 GIT binary patch delta 402 zcmca6^G#vHQ%1JZ;>7gSfXQfQ&RJb6>Jp@Cf{OAlZVJ;L!~r{dYoAqhMQPY0FUd$P(nHb*R|hplgL(Jl^~|h{0h4Di z%dkNOFEYajr2lw@QUL+pn*%o^-01%<5Q{JiKQ zbtIReDTkQ3*^;%J2^LC%?8?f>=4&eIKuuFXcGP4ac4bb8c6Cj~&AZsU+2oM5K{O#- JJ=vB|5&()ViwOV# delta 41 zcmV+^0M`HZAl4kPdv427Cguz6pT_lVuPQlU)(z diff --git a/mobile/openapi/lib/model/usage_by_user_dto.dart b/mobile/openapi/lib/model/usage_by_user_dto.dart index e6f9216d74572cf561ff501fd8e4107f49f1ee42..80235915fea8e8b4cc5cdca921bd0e252631d64d 100644 GIT binary patch delta 408 zcmdn4@K9yLQ%07=^wfaKy^NBarNuyISY}G<JmW~ zac(4qlk-{58NiLVRY7u&4#Xyi2~ZiRah9y*jJ|MP>ahy83MCnt#Sj<3JOgr=f { photos: 10, videos: 11, usage: 12_345, + usagePhotos: 1, + usageVideos: 11_345, quotaSizeInBytes: 0, }, { @@ -193,6 +195,8 @@ describe(ServerService.name, () => { photos: 10, videos: 20, usage: 123_456, + usagePhotos: 100, + usageVideos: 23_456, quotaSizeInBytes: 0, }, { @@ -201,6 +205,8 @@ describe(ServerService.name, () => { photos: 100, videos: 0, usage: 987_654, + usagePhotos: 900, + usageVideos: 87_654, quotaSizeInBytes: 0, }, ]); @@ -209,11 +215,15 @@ describe(ServerService.name, () => { photos: 120, videos: 31, usage: 1_123_455, + usagePhotos: 1001, + usageVideos: 122_455, usageByUser: [ { photos: 10, quotaSizeInBytes: 0, usage: 12_345, + usagePhotos: 1, + usageVideos: 11_345, userName: '1 User', userId: 'user1', videos: 11, @@ -222,6 +232,8 @@ describe(ServerService.name, () => { photos: 10, quotaSizeInBytes: 0, usage: 123_456, + usagePhotos: 100, + usageVideos: 23_456, userName: '2 User', userId: 'user2', videos: 20, @@ -230,6 +242,8 @@ describe(ServerService.name, () => { photos: 100, quotaSizeInBytes: 0, usage: 987_654, + usagePhotos: 900, + usageVideos: 87_654, userName: '3 User', userId: 'user3', videos: 0, diff --git a/server/src/services/server.service.ts b/server/src/services/server.service.ts index 3fc319a2fd..7df322a84e 100644 --- a/server/src/services/server.service.ts +++ b/server/src/services/server.service.ts @@ -126,11 +126,16 @@ export class ServerService extends BaseService { usage.photos = user.photos; usage.videos = user.videos; usage.usage = user.usage; + usage.usagePhotos = user.usagePhotos; + usage.usageVideos = user.usageVideos; usage.quotaSizeInBytes = user.quotaSizeInBytes; serverStats.photos += usage.photos; serverStats.videos += usage.videos; serverStats.usage += usage.usage; + serverStats.usagePhotos += usage.usagePhotos; + serverStats.usageVideos += usage.usageVideos; + serverStats.usageByUser.push(usage); } diff --git a/web/src/lib/components/admin-page/server-stats/server-stats-panel.svelte b/web/src/lib/components/admin-page/server-stats/server-stats-panel.svelte index feab6a9c6d..bb288511ac 100644 --- a/web/src/lib/components/admin-page/server-stats/server-stats-panel.svelte +++ b/web/src/lib/components/admin-page/server-stats/server-stats-panel.svelte @@ -16,6 +16,8 @@ photos: 0, videos: 0, usage: 0, + usagePhotos: 0, + usageVideos: 0, usageByUser: [], }, }: Props = $props(); @@ -105,8 +107,12 @@ class="flex h-[50px] w-full place-items-center text-center odd:bg-immich-gray even:bg-immich-bg odd:dark:bg-immich-dark-gray/75 even:dark:bg-immich-dark-gray/50" > {user.userName} - {user.photos.toLocaleString($locale)} - {user.videos.toLocaleString($locale)} + {user.photos.toLocaleString($locale)} ({getByteUnitString(user.usagePhotos, $locale, 0)}) + {user.videos.toLocaleString($locale)} ({getByteUnitString(user.usageVideos, $locale, 0)}) {getByteUnitString(user.usage, $locale, 0)} {#if user.quotaSizeInBytes}