2025-11-03 22:09:05 +00:00
|
|
|
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
|
|
|
|
|
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
|
|
|
|
|
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
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';
|
|
|
|
|
|
|
|
|
|
export class GroupInsertionCache {
|
|
|
|
|
#lookupCache: {
|
2025-11-03 22:09:05 +00:00
|
|
|
[year: number]: { [month: number]: { [day: number]: TimelineDay } };
|
2025-06-10 10:30:13 -04:00
|
|
|
} = {};
|
|
|
|
|
unprocessedAssets: TimelineAsset[] = [];
|
2025-10-26 17:26:33 +00:00
|
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
2025-11-03 22:09:05 +00:00
|
|
|
changedDays = new Set<TimelineDay>();
|
2025-10-26 17:26:33 +00:00
|
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
2025-11-03 22:09:05 +00:00
|
|
|
newDays = new Set<TimelineDay>();
|
2025-06-10 10:30:13 -04:00
|
|
|
|
2025-11-03 22:09:05 +00:00
|
|
|
getDay({ year, month, day }: TimelineDate): TimelineDay | undefined {
|
2025-06-10 10:30:13 -04:00
|
|
|
return this.#lookupCache[year]?.[month]?.[day];
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-03 22:09:05 +00:00
|
|
|
setDay(day: TimelineDay, { year, month, day: dayNumber }: 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] = {};
|
|
|
|
|
}
|
2025-11-03 22:09:05 +00:00
|
|
|
this.#lookupCache[year][month][dayNumber] = day;
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-03 22:09:05 +00:00
|
|
|
get existingDays() {
|
|
|
|
|
return setDifference(this.changedDays, this.newDays);
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-03 22:09:05 +00:00
|
|
|
get updatedMonths() {
|
2025-10-26 17:26:33 +00:00
|
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
2025-11-03 22:09:05 +00:00
|
|
|
const months = new Set<TimelineMonth>();
|
|
|
|
|
for (const day of this.changedDays) {
|
|
|
|
|
months.add(day.month);
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
2025-11-03 22:09:05 +00:00
|
|
|
return months;
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-03 22:09:05 +00:00
|
|
|
get monthsWithNewDays() {
|
2025-10-26 17:26:33 +00:00
|
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
2025-11-03 22:09:05 +00:00
|
|
|
const months = new Set<TimelineMonth>();
|
|
|
|
|
for (const day of this.newDays) {
|
|
|
|
|
months.add(day.month);
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
2025-11-03 22:09:05 +00:00
|
|
|
return months;
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-03 22:09:05 +00:00
|
|
|
sort(month: TimelineMonth, sortOrder: AssetOrder = AssetOrder.Desc) {
|
|
|
|
|
for (const day of this.changedDays) {
|
|
|
|
|
day.sortAssets(sortOrder);
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
2025-11-03 22:09:05 +00:00
|
|
|
for (const day of this.newDays) {
|
|
|
|
|
day.sortAssets(sortOrder);
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
2025-11-03 22:09:05 +00:00
|
|
|
if (this.newDays.size > 0) {
|
|
|
|
|
month.sortDays();
|
2025-06-10 10:30:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|