feat: faster access checks

This commit is contained in:
Jason Rasmussen
2025-09-11 14:06:27 -04:00
parent 722a464e23
commit 42e1e0c66a
17 changed files with 324 additions and 101 deletions
@@ -5,7 +5,7 @@
import { getAssetPlaybackUrl, getAssetThumbnailUrl } from '$lib/utils';
import { timeToSeconds } from '$lib/utils/date-time';
import { getAltText } from '$lib/utils/thumbnail-util';
import { AssetMediaSize, AssetVisibility } from '@immich/sdk';
import { AccessHint, AssetMediaSize, AssetVisibility } from '@immich/sdk';
import {
mdiArchiveArrowDownOutline,
mdiCameraBurst,
@@ -20,6 +20,7 @@
import { authManager } from '$lib/managers/auth-manager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import { mobileDevice } from '$lib/stores/mobile-device.svelte';
import { user } from '$lib/stores/user.store';
import { moveFocus } from '$lib/utils/focus-util';
import { currentUrlReplaceAssetId } from '$lib/utils/navigation';
import { TUNABLES } from '$lib/utils/tunables';
@@ -45,6 +46,7 @@
imageClass?: ClassValue;
brokenAssetClass?: ClassValue;
dimmed?: boolean;
hint?: AccessHint;
onClick?: (asset: TimelineAsset) => void;
onSelect?: (asset: TimelineAsset) => void;
onMouseEvent?: (event: { isMouseOver: boolean; selectedGroupIndex: number }) => void;
@@ -69,6 +71,7 @@
imageClass = '',
brokenAssetClass = '',
dimmed = false,
hint,
}: Props = $props();
let {
@@ -313,7 +316,12 @@
<ImageThumbnail
class={imageClass}
{brokenAssetClass}
url={getAssetThumbnailUrl({ id: asset.id, size: AssetMediaSize.Thumbnail, cacheKey: asset.thumbhash })}
url={getAssetThumbnailUrl({
id: asset.id,
size: AssetMediaSize.Thumbnail,
cacheKey: asset.thumbhash,
hint: asset.ownerId === $user.id ? undefined : hint,
})}
altText={$getAltText(asset)}
widthStyle="{width}px"
heightStyle="{height}px"
@@ -232,6 +232,7 @@
disabled={dayGroup.monthGroup.timelineManager.albumAssets.has(asset.id)}
thumbnailWidth={position.width}
thumbnailHeight={position.height}
hint={timelineManager.hint}
/>
{#if customLayout}
{@render customLayout(asset)}
@@ -1,4 +1,4 @@
import { AssetOrder, getAssetInfo, getTimeBuckets } from '@immich/sdk';
import { AccessHint, AssetOrder, getAssetInfo, getTimeBuckets } from '@immich/sdk';
import { authManager } from '$lib/managers/auth-manager.svelte';
@@ -38,6 +38,7 @@ import type {
} from './types';
export class TimelineManager {
hint?: AccessHint;
isInitialized = $state(false);
months: MonthGroup[] = $state([]);
topSectionHeight = $state(0);
@@ -97,7 +98,9 @@ export class TimelineManager {
monthGroup: undefined,
});
constructor() {}
constructor(options?: { hint?: AccessHint }) {
this.hint = options?.hint;
}
setLayoutOptions({ headerHeight = 48, rowHeight = 235, gap = 12 }: TimelineManagerLayoutOptions) {
let changed = false;
+6 -3
View File
@@ -5,6 +5,7 @@ import { lang } from '$lib/stores/preferences.store';
import { serverConfig } from '$lib/stores/server-config.store';
import { handleError } from '$lib/utils/handle-error';
import {
AccessHint,
AssetJobName,
AssetMediaSize,
JobName,
@@ -197,12 +198,14 @@ export const getAssetOriginalUrl = (options: string | AssetUrlOptions) => {
return createUrl(getAssetOriginalPath(id), { ...authManager.params, c: cacheKey });
};
export const getAssetThumbnailUrl = (options: string | (AssetUrlOptions & { size?: AssetMediaSize })) => {
export const getAssetThumbnailUrl = (
options: string | (AssetUrlOptions & { size?: AssetMediaSize; hint?: AccessHint }),
) => {
if (typeof options === 'string') {
options = { id: options };
}
const { id, size, cacheKey } = options;
return createUrl(getAssetThumbnailPath(id), { ...authManager.params, size, c: cacheKey });
const { id, size, cacheKey, hint } = options;
return createUrl(getAssetThumbnailPath(id), { ...authManager.params, size, c: cacheKey, hint });
};
export const getAssetPlaybackUrl = (options: string | AssetUrlOptions) => {
@@ -59,6 +59,7 @@
type AssetGridRouteSearchParams,
} from '$lib/utils/navigation';
import {
AccessHint,
AlbumUserRole,
AssetOrder,
AssetVisibility,
@@ -328,7 +329,7 @@
}
});
let timelineManager = new TimelineManager();
let timelineManager = new TimelineManager({ hint: AccessHint.Album });
$effect(() => {
if (viewMode === AlbumPageViewMode.VIEW) {
@@ -10,7 +10,7 @@
import { AppRoute } from '$lib/constants';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { AssetVisibility } from '@immich/sdk';
import { AccessHint, AssetVisibility } from '@immich/sdk';
import { mdiArrowLeft, mdiPlus } from '@mdi/js';
import { onDestroy } from 'svelte';
import { t } from 'svelte-i18n';
@@ -22,7 +22,7 @@
let { data }: Props = $props();
const timelineManager = new TimelineManager();
const timelineManager = new TimelineManager({ hint: AccessHint.Partner });
$effect(
() =>
void timelineManager.updateOptions({