mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
refactor count map
This commit is contained in:
parent
23d2abc5d1
commit
4c6aa0568b
2 changed files with 8 additions and 8 deletions
|
|
@ -79,7 +79,6 @@ export class AlbumService extends BaseService {
|
|||
const album = await this.findOrFail(id, { withAssets });
|
||||
const [albumMetadataForIds] = await this.albumRepository.getMetadataForIds([album.id]);
|
||||
|
||||
// Determine if the album is shared (shared users or shared link)
|
||||
const hasSharedUsers = album.albumUsers && album.albumUsers.length > 0;
|
||||
const hasSharedLink = album.sharedLinks && album.sharedLinks.length > 0;
|
||||
const isShared = hasSharedUsers || hasSharedLink;
|
||||
|
|
@ -90,7 +89,6 @@ export class AlbumService extends BaseService {
|
|||
endDate: albumMetadataForIds?.endDate ?? undefined,
|
||||
assetCount: albumMetadataForIds?.assetCount ?? 0,
|
||||
lastModifiedAssetTimestamp: albumMetadataForIds?.lastModifiedAssetTimestamp ?? undefined,
|
||||
// Fetch contributor counts only for shared albums
|
||||
contributorCounts: isShared ? await this.albumRepository.getContributorCounts(album.id) : undefined,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,12 @@
|
|||
let isOwned = $derived(currentUser?.id == album.ownerId);
|
||||
|
||||
// Build a map of contributor counts by user id; avoid casts/derived
|
||||
const contributorMap: Record<string, number> = Object.fromEntries(
|
||||
(album.contributorCounts ?? []).map(({ userId, assetCount }) => [userId, assetCount]),
|
||||
);
|
||||
const getCount = (userId: string) => contributorMap[userId] ?? 0;
|
||||
const contributorCounts: Record<string, number> = {};
|
||||
if (album.contributorCounts) {
|
||||
for (const { userId, assetCount } of album.contributorCounts) {
|
||||
contributorCounts[userId] = assetCount;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
|
|
@ -117,9 +119,9 @@
|
|||
{:else}
|
||||
{$t('role_editor')}
|
||||
{/if}
|
||||
{#if getCount(user.id) > 0}
|
||||
{#if user.id in contributorCounts}
|
||||
<span>-</span>
|
||||
{$t('items_count', { values: { count: getCount(user.id) } })}
|
||||
{$t('items_count', { values: { count: contributorCounts[user.id] } })}
|
||||
{/if}
|
||||
</Text>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue