Skip to content

Commit d6b39a4

Browse files
authored
feat: improve performance: don't sort timeline buckets from server (#24032)
1 parent 75d23fe commit d6b39a4

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

web/src/lib/managers/timeline-manager/group-insertion-cache.svelte.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { setDifference, type TimelineDate } from '$lib/utils/timeline-util';
22
import { AssetOrder } from '@immich/sdk';
3-
import { SvelteSet } from 'svelte/reactivity';
43
import type { DayGroup } from './day-group.svelte';
54
import type { MonthGroup } from './month-group.svelte';
65
import type { TimelineAsset } from './types';
@@ -10,8 +9,10 @@ export class GroupInsertionCache {
109
[year: number]: { [month: number]: { [day: number]: DayGroup } };
1110
} = {};
1211
unprocessedAssets: TimelineAsset[] = [];
13-
changedDayGroups = new SvelteSet<DayGroup>();
14-
newDayGroups = new SvelteSet<DayGroup>();
12+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
13+
changedDayGroups = new Set<DayGroup>();
14+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
15+
newDayGroups = new Set<DayGroup>();
1516

1617
getDayGroup({ year, month, day }: TimelineDate): DayGroup | undefined {
1718
return this.#lookupCache[year]?.[month]?.[day];
@@ -32,15 +33,17 @@ export class GroupInsertionCache {
3233
}
3334

3435
get updatedBuckets() {
35-
const updated = new SvelteSet<MonthGroup>();
36+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
37+
const updated = new Set<MonthGroup>();
3638
for (const group of this.changedDayGroups) {
3739
updated.add(group.monthGroup);
3840
}
3941
return updated;
4042
}
4143

4244
get bucketsWithNewDayGroups() {
43-
const updated = new SvelteSet<MonthGroup>();
45+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
46+
const updated = new Set<MonthGroup>();
4447
for (const group of this.newDayGroups) {
4548
updated.add(group.monthGroup);
4649
}

web/src/lib/managers/timeline-manager/internal/load-support.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function loadFromTimeBuckets(
4646
}
4747
}
4848

49-
const unprocessedAssets = monthGroup.addAssets(bucketResponse);
49+
const unprocessedAssets = monthGroup.addAssets(bucketResponse, true);
5050
if (unprocessedAssets.length > 0) {
5151
console.error(
5252
`Warning: getTimeBucket API returning assets not in requested month: ${monthGroup.yearMonth.month}, ${JSON.stringify(

web/src/lib/managers/timeline-manager/month-group.svelte.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class MonthGroup {
153153
};
154154
}
155155

156-
addAssets(bucketAssets: TimeBucketAssetResponseDto) {
156+
addAssets(bucketAssets: TimeBucketAssetResponseDto, preSorted: boolean) {
157157
const addContext = new GroupInsertionCache();
158158
for (let i = 0; i < bucketAssets.id.length; i++) {
159159
const { localDateTime, fileCreatedAt } = getTimes(
@@ -194,6 +194,9 @@ export class MonthGroup {
194194
}
195195
this.addTimelineAsset(timelineAsset, addContext);
196196
}
197+
if (preSorted) {
198+
return addContext.unprocessedAssets;
199+
}
197200

198201
for (const group of addContext.existingDayGroups) {
199202
group.sortAssets(this.#sortOrder);

0 commit comments

Comments
 (0)