mirror of
https://github.com/immich-app/immich.git
synced 2025-12-19 09:13:14 +03:00
Don't sort initial load of month from server
This commit is contained in:
@@ -31,7 +31,9 @@ export class DayGroup {
|
|||||||
this.monthGroup = monthGroup;
|
this.monthGroup = monthGroup;
|
||||||
this.day = day;
|
this.day = day;
|
||||||
this.groupTitle = groupTitle;
|
this.groupTitle = groupTitle;
|
||||||
onCreateDayGroup(this);
|
if (import.meta.env.DEV) {
|
||||||
|
onCreateDayGroup(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get top() {
|
get top() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { setDifference, type TimelineDate } from '$lib/utils/timeline-util';
|
import { setDifference, type TimelineDate } from '$lib/utils/timeline-util';
|
||||||
import { AssetOrder } from '@immich/sdk';
|
import { AssetOrder } from '@immich/sdk';
|
||||||
import { SvelteSet } from 'svelte/reactivity';
|
|
||||||
import type { DayGroup } from './day-group.svelte';
|
import type { DayGroup } from './day-group.svelte';
|
||||||
import type { MonthGroup } from './month-group.svelte';
|
import type { MonthGroup } from './month-group.svelte';
|
||||||
import type { TimelineAsset } from './types';
|
import type { TimelineAsset } from './types';
|
||||||
@@ -10,8 +9,10 @@ export class GroupInsertionCache {
|
|||||||
[year: number]: { [month: number]: { [day: number]: DayGroup } };
|
[year: number]: { [month: number]: { [day: number]: DayGroup } };
|
||||||
} = {};
|
} = {};
|
||||||
unprocessedAssets: TimelineAsset[] = [];
|
unprocessedAssets: TimelineAsset[] = [];
|
||||||
changedDayGroups = new SvelteSet<DayGroup>();
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
||||||
newDayGroups = new SvelteSet<DayGroup>();
|
changedDayGroups = new Set<DayGroup>();
|
||||||
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
||||||
|
newDayGroups = new Set<DayGroup>();
|
||||||
|
|
||||||
getDayGroup({ year, month, day }: TimelineDate): DayGroup | undefined {
|
getDayGroup({ year, month, day }: TimelineDate): DayGroup | undefined {
|
||||||
return this.#lookupCache[year]?.[month]?.[day];
|
return this.#lookupCache[year]?.[month]?.[day];
|
||||||
@@ -32,7 +33,8 @@ export class GroupInsertionCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get updatedBuckets() {
|
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) {
|
for (const group of this.changedDayGroups) {
|
||||||
updated.add(group.monthGroup);
|
updated.add(group.monthGroup);
|
||||||
}
|
}
|
||||||
@@ -40,7 +42,8 @@ export class GroupInsertionCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get bucketsWithNewDayGroups() {
|
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) {
|
for (const group of this.newDayGroups) {
|
||||||
updated.add(group.monthGroup);
|
updated.add(group.monthGroup);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export async function loadFromTimeBuckets(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const unprocessedAssets = monthGroup.addAssets(bucketResponse);
|
const unprocessedAssets = monthGroup.addAssets(bucketResponse, true);
|
||||||
if (unprocessedAssets.length > 0) {
|
if (unprocessedAssets.length > 0) {
|
||||||
console.error(
|
console.error(
|
||||||
`Warning: getTimeBucket API returning assets not in requested month: ${monthGroup.yearMonth.month}, ${JSON.stringify(
|
`Warning: getTimeBucket API returning assets not in requested month: ${monthGroup.yearMonth.month}, ${JSON.stringify(
|
||||||
|
|||||||
@@ -76,7 +76,9 @@ export class MonthGroup {
|
|||||||
if (loaded) {
|
if (loaded) {
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
}
|
}
|
||||||
onCreateMonthGroup(this);
|
if (import.meta.env.DEV) {
|
||||||
|
onCreateMonthGroup(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set intersecting(newValue: boolean) {
|
set intersecting(newValue: boolean) {
|
||||||
@@ -161,7 +163,7 @@ export class MonthGroup {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
addAssets(bucketAssets: TimeBucketAssetResponseDto) {
|
addAssets(bucketAssets: TimeBucketAssetResponseDto, preSorted: boolean) {
|
||||||
const addContext = new GroupInsertionCache();
|
const addContext = new GroupInsertionCache();
|
||||||
for (let i = 0; i < bucketAssets.id.length; i++) {
|
for (let i = 0; i < bucketAssets.id.length; i++) {
|
||||||
const { localDateTime, fileCreatedAt } = getTimes(
|
const { localDateTime, fileCreatedAt } = getTimes(
|
||||||
@@ -202,17 +204,17 @@ export class MonthGroup {
|
|||||||
}
|
}
|
||||||
this.addTimelineAsset(timelineAsset, addContext);
|
this.addTimelineAsset(timelineAsset, addContext);
|
||||||
}
|
}
|
||||||
|
if (!preSorted) {
|
||||||
|
for (const group of addContext.existingDayGroups) {
|
||||||
|
group.sortAssets(this.#sortOrder);
|
||||||
|
}
|
||||||
|
|
||||||
for (const group of addContext.existingDayGroups) {
|
if (addContext.newDayGroups.size > 0) {
|
||||||
group.sortAssets(this.#sortOrder);
|
this.sortDayGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
addContext.sort(this, this.#sortOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addContext.newDayGroups.size > 0) {
|
|
||||||
this.sortDayGroups();
|
|
||||||
}
|
|
||||||
|
|
||||||
addContext.sort(this, this.#sortOrder);
|
|
||||||
|
|
||||||
return addContext.unprocessedAssets;
|
return addContext.unprocessedAssets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user