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 album = await this.findOrFail(id, { withAssets });
|
||||||
const [albumMetadataForIds] = await this.albumRepository.getMetadataForIds([album.id]);
|
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 hasSharedUsers = album.albumUsers && album.albumUsers.length > 0;
|
||||||
const hasSharedLink = album.sharedLinks && album.sharedLinks.length > 0;
|
const hasSharedLink = album.sharedLinks && album.sharedLinks.length > 0;
|
||||||
const isShared = hasSharedUsers || hasSharedLink;
|
const isShared = hasSharedUsers || hasSharedLink;
|
||||||
|
|
@ -90,7 +89,6 @@ export class AlbumService extends BaseService {
|
||||||
endDate: albumMetadataForIds?.endDate ?? undefined,
|
endDate: albumMetadataForIds?.endDate ?? undefined,
|
||||||
assetCount: albumMetadataForIds?.assetCount ?? 0,
|
assetCount: albumMetadataForIds?.assetCount ?? 0,
|
||||||
lastModifiedAssetTimestamp: albumMetadataForIds?.lastModifiedAssetTimestamp ?? undefined,
|
lastModifiedAssetTimestamp: albumMetadataForIds?.lastModifiedAssetTimestamp ?? undefined,
|
||||||
// Fetch contributor counts only for shared albums
|
|
||||||
contributorCounts: isShared ? await this.albumRepository.getContributorCounts(album.id) : undefined,
|
contributorCounts: isShared ? await this.albumRepository.getContributorCounts(album.id) : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,12 @@
|
||||||
let isOwned = $derived(currentUser?.id == album.ownerId);
|
let isOwned = $derived(currentUser?.id == album.ownerId);
|
||||||
|
|
||||||
// Build a map of contributor counts by user id; avoid casts/derived
|
// Build a map of contributor counts by user id; avoid casts/derived
|
||||||
const contributorMap: Record<string, number> = Object.fromEntries(
|
const contributorCounts: Record<string, number> = {};
|
||||||
(album.contributorCounts ?? []).map(({ userId, assetCount }) => [userId, assetCount]),
|
if (album.contributorCounts) {
|
||||||
);
|
for (const { userId, assetCount } of album.contributorCounts) {
|
||||||
const getCount = (userId: string) => contributorMap[userId] ?? 0;
|
contributorCounts[userId] = assetCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -117,9 +119,9 @@
|
||||||
{:else}
|
{:else}
|
||||||
{$t('role_editor')}
|
{$t('role_editor')}
|
||||||
{/if}
|
{/if}
|
||||||
{#if getCount(user.id) > 0}
|
{#if user.id in contributorCounts}
|
||||||
<span>-</span>
|
<span>-</span>
|
||||||
{$t('items_count', { values: { count: getCount(user.id) } })}
|
{$t('items_count', { values: { count: contributorCounts[user.id] } })}
|
||||||
{/if}
|
{/if}
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue