2025-07-30 12:21:02 -04:00
|
|
|
import { setDifference, type TimelineDate } from '$lib/utils/timeline-util';
|
2025-06-10 10:30:13 -04:00
|
|
|
import { AssetOrder } from '@immich/sdk';
|
|
|
|
|
import type { DayGroup } from './day-group.svelte';
|
|
|
|
|
import type { MonthGroup } from './month-group.svelte';
|
|
|
|
|
import type { TimelineAsset } from './types';
|
|
|
|
|
|
|
|
|
|
export class GroupInsertionCache {
|
|
|
|
|
#lookupCache: {
|
|
|
|
|
[year: number]: { [month: number]: { [day: number]: DayGroup } };
|
|
|
|
|
} = {};
|
|
|
|
|
unprocessedAssets: TimelineAsset[] = [];
|
2025-10-26 17:26:33 +00:00
|
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
|
|
|
changedDayGroups = new Set<DayGroup>();
|
|
|
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
|
|
|
newDayGroups = new Set<DayGroup>();
|
2025-06-10 10:30:13 -04:00
|
|
|
|
2025-07-30 12:21:02 -04:00
|
|
|
getDayGroup({ year, month, day }: TimelineDate): DayGroup | undefined {
|
2025-06-10 10:30:13 -04:00
|
|
|
return this.#lookupCache[year]?.[month]?.[day];
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 12:21:02 -04:00
|
|
|
setDayGroup(dayGroup: DayGroup, { year, month, day }: TimelineDate) {
|
2025-06-10 10:30:13 -04:00
|
|
|
if (!this.#lookupCache[year]) {
|
|
|
|
|
this.#lookupCache[year] = {};
|
|
|
|
|
}
|
|
|
|
|
if (!this.#lookupCache[year][month]) {
|
|
|
|
|
this.#lookupCache[year][month] = {};
|
|
|
|
|
}
|
|
|
|
|
this.#lookupCache[year][month][day] = dayGroup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get existingDayGroups() {
|
2025-06-12 11:41:19 -05:00
|
|
|
return setDifference(this.changedDayGroups, this.newDayGroups);
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get updatedBuckets() {
|
2025-10-26 17:26:33 +00:00
|
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
|
|
|
const updated = new Set<MonthGroup>();
|
2025-06-10 10:30:13 -04:00
|
|
|
for (const group of this.changedDayGroups) {
|
|
|
|
|
updated.add(group.monthGroup);
|
|
|
|
|
}
|
|
|
|
|
return updated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get bucketsWithNewDayGroups() {
|
2025-10-26 17:26:33 +00:00
|
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
|
|
|
const updated = new Set<MonthGroup>();
|
2025-06-10 10:30:13 -04:00
|
|
|
for (const group of this.newDayGroups) {
|
|
|
|
|
updated.add(group.monthGroup);
|
|
|
|
|
}
|
|
|
|
|
return updated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sort(monthGroup: MonthGroup, sortOrder: AssetOrder = AssetOrder.Desc) {
|
|
|
|
|
for (const group of this.changedDayGroups) {
|
|
|
|
|
group.sortAssets(sortOrder);
|
|
|
|
|
}
|
|
|
|
|
for (const group of this.newDayGroups) {
|
|
|
|
|
group.sortAssets(sortOrder);
|
|
|
|
|
}
|
|
|
|
|
if (this.newDayGroups.size > 0) {
|
|
|
|
|
monthGroup.sortDayGroups();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|