Skip to content

High performance self-hosted photo and video management solution.

feat: improve performance: don't sort timeline buckets from server (#24032)

Min Idzelisd6b39a464d3c
diff --git a/web/src/lib/managers/timeline-manager/group-insertion-cache.svelte.ts b/web/src/lib/managers/timeline-manager/group-insertion-cache.svelte.ts
index aa4bae8919..566b11b8b7 100644
--- a/web/src/lib/managers/timeline-manager/group-insertion-cache.svelte.ts
+++ b/web/src/lib/managers/timeline-manager/group-insertion-cache.svelte.ts
@@ -1,6 +1,5 @@
import { setDifference, type TimelineDate } from '$lib/utils/timeline-util';
import { AssetOrder } from '@immich/sdk';
-import { SvelteSet } from 'svelte/reactivity';
import type { DayGroup } from './day-group.svelte';
import type { MonthGroup } from './month-group.svelte';
import type { TimelineAsset } from './types';
@@ -10,8 +9,10 @@ export class GroupInsertionCache {
[year: number]: { [month: number]: { [day: number]: DayGroup } };
} = {};
unprocessedAssets: TimelineAsset[] = [];
- changedDayGroups = new SvelteSet<DayGroup>();
- newDayGroups = new SvelteSet<DayGroup>();
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
+ changedDayGroups = new Set<DayGroup>();
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
+ newDayGroups = new Set<DayGroup>();
getDayGroup({ year, month, day }: TimelineDate): DayGroup | undefined {
return this.#lookupCache[year]?.[month]?.[day];
@@ -32,7 +33,8 @@ export class GroupInsertionCache {
}
get updatedBuckets() {
- const updated = new SvelteSet<MonthGroup>();
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
+ const updated = new Set<MonthGroup>();
for (const group of this.changedDayGroups) {
updated.add(group.monthGroup);
}
@@ -40,7 +42,8 @@ export class GroupInsertionCache {
}
get bucketsWithNewDayGroups() {
- const updated = new SvelteSet<MonthGroup>();
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
+ const updated = new Set<MonthGroup>();
for (const group of this.newDayGroups) {
updated.add(group.monthGroup);
}
diff --git a/web/src/lib/managers/timeline-manager/internal/load-support.svelte.ts b/web/src/lib/managers/timeline-manager/internal/load-support.svelte.ts
index ec50e3d75e..859e818583 100644
--- a/web/src/lib/managers/timeline-manager/internal/load-support.svelte.ts
+++ b/web/src/lib/managers/timeline-manager/internal/load-support.svelte.ts
@@ -46,7 +46,7 @@ export async function loadFromTimeBuckets(
}
}
- const unprocessedAssets = monthGroup.addAssets(bucketResponse);
+ const unprocessedAssets = monthGroup.addAssets(bucketResponse, true);
if (unprocessedAssets.length > 0) {
console.error(
`Warning: getTimeBucket API returning assets not in requested month: ${monthGroup.yearMonth.month}, ${JSON.stringify(
diff --git a/web/src/lib/managers/timeline-manager/month-group.svelte.ts b/web/src/lib/managers/timeline-manager/month-group.svelte.ts
index bef512c226..1d9e1bbaa7 100644
--- a/web/src/lib/managers/timeline-manager/month-group.svelte.ts
+++ b/web/src/lib/managers/timeline-manager/month-group.svelte.ts
@@ -153,7 +153,7 @@ export class MonthGroup {
};
}
- addAssets(bucketAssets: TimeBucketAssetResponseDto) {
+ addAssets(bucketAssets: TimeBucketAssetResponseDto, preSorted: boolean) {
const addContext = new GroupInsertionCache();
for (let i = 0; i < bucketAssets.id.length; i++) {
const { localDateTime, fileCreatedAt } = getTimes(
@@ -194,6 +194,9 @@ export class MonthGroup {
}
this.addTimelineAsset(timelineAsset, addContext);
}
+ if (preSorted) {
+ return addContext.unprocessedAssets;
+ }
for (const group of addContext.existingDayGroups) {
group.sortAssets(this.#sortOrder);