mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix(web): refresh memories hourly (#28114)
This commit is contained in:
@@ -33,6 +33,8 @@ class MemoryManager {
|
|||||||
if (authManager.authenticated) {
|
if (authManager.authenticated) {
|
||||||
void this.initialize();
|
void this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.scheduleHourlyRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
ready() {
|
ready() {
|
||||||
@@ -132,6 +134,29 @@ class MemoryManager {
|
|||||||
const memories = await searchMemories({ $for: asLocalTimeISO(DateTime.now()) });
|
const memories = await searchMemories({ $for: asLocalTimeISO(DateTime.now()) });
|
||||||
this.memories = memories.filter((memory) => memory.assets.length > 0);
|
this.memories = memories.filter((memory) => memory.assets.length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private scheduleHourlyRefresh() {
|
||||||
|
const now = DateTime.utc();
|
||||||
|
let nextEvent = now.set({ minute: 0, second: 5 });
|
||||||
|
|
||||||
|
if (nextEvent <= now) {
|
||||||
|
nextEvent = nextEvent.plus({ hours: 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialDelay = nextEvent.diff(now).as('milliseconds');
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.#loading = this.load();
|
||||||
|
|
||||||
|
// Schedule subsequent events hourly
|
||||||
|
setInterval(
|
||||||
|
() => {
|
||||||
|
this.#loading = this.load();
|
||||||
|
},
|
||||||
|
60 * 60 * 1000,
|
||||||
|
);
|
||||||
|
}, initialDelay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const memoryManager = new MemoryManager();
|
export const memoryManager = new MemoryManager();
|
||||||
|
|||||||
Reference in New Issue
Block a user