mirror of
https://github.com/immich-app/immich.git
synced 2025-12-11 17:23:13 +03:00
- Rename classes: DayGroup → TimelineDay, MonthGroup → TimelineMonth - Use short variable names: dayGroup → day, monthGroup → month - Update all method names and properties for consistency - Convert relative imports to $lib alias convention No functional changes.
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
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';
|
|
import { setDifference, type TimelineDate } from '$lib/utils/timeline-util';
|
|
import { AssetOrder } from '@immich/sdk';
|
|
|
|
export class GroupInsertionCache {
|
|
#lookupCache: {
|
|
[year: number]: { [month: number]: { [day: number]: TimelineDay } };
|
|
} = {};
|
|
unprocessedAssets: TimelineAsset[] = [];
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
changedDays = new Set<TimelineDay>();
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
newDays = new Set<TimelineDay>();
|
|
|
|
getDay({ year, month, day }: TimelineDate): TimelineDay | undefined {
|
|
return this.#lookupCache[year]?.[month]?.[day];
|
|
}
|
|
|
|
setDay(day: TimelineDay, { year, month, day: dayNumber }: TimelineDate) {
|
|
if (!this.#lookupCache[year]) {
|
|
this.#lookupCache[year] = {};
|
|
}
|
|
if (!this.#lookupCache[year][month]) {
|
|
this.#lookupCache[year][month] = {};
|
|
}
|
|
this.#lookupCache[year][month][dayNumber] = day;
|
|
}
|
|
|
|
get existingDays() {
|
|
return setDifference(this.changedDays, this.newDays);
|
|
}
|
|
|
|
get updatedMonths() {
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
const months = new Set<TimelineMonth>();
|
|
for (const day of this.changedDays) {
|
|
months.add(day.month);
|
|
}
|
|
return months;
|
|
}
|
|
|
|
get monthsWithNewDays() {
|
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
const months = new Set<TimelineMonth>();
|
|
for (const day of this.newDays) {
|
|
months.add(day.month);
|
|
}
|
|
return months;
|
|
}
|
|
|
|
sort(month: TimelineMonth, sortOrder: AssetOrder = AssetOrder.Desc) {
|
|
for (const day of this.changedDays) {
|
|
day.sortAssets(sortOrder);
|
|
}
|
|
for (const day of this.newDays) {
|
|
day.sortAssets(sortOrder);
|
|
}
|
|
if (this.newDays.size > 0) {
|
|
month.sortDays();
|
|
}
|
|
}
|
|
}
|