Restore initial draft of video seeking.

This commit is contained in:
Dermot Duffy
2023-01-24 19:36:54 -08:00
parent a718e5febe
commit 208795d7b3
5 changed files with 70 additions and 49 deletions
+4
View File
@@ -197,6 +197,7 @@ export class FrigateCameraManagerEngine implements CameraManagerEngine {
engine: Engine.Frigate,
events: await getEvents(hass, nativeQuery),
expiry: add(new Date(), { seconds: EVENT_REQUEST_CACHE_MAX_AGE_SECONDS }),
cached: false,
};
}
@@ -257,6 +258,7 @@ export class FrigateCameraManagerEngine implements CameraManagerEngine {
expiry: add(new Date(), {
seconds: RECORDING_SUMMARY_REQUEST_CACHE_MAX_AGE_SECONDS,
}),
cached: false,
};
}
@@ -285,6 +287,7 @@ export class FrigateCameraManagerEngine implements CameraManagerEngine {
type: QueryResultsType.RecordingSegments,
engine: Engine.Frigate,
segments: cachedSegments,
cached: true,
};
}
@@ -304,6 +307,7 @@ export class FrigateCameraManagerEngine implements CameraManagerEngine {
type: QueryResultsType.RecordingSegments,
engine: Engine.Frigate,
segments: segments,
cached: false,
};
}
+8 -5
View File
@@ -210,10 +210,7 @@ export class CameraManager {
orderBy(
// Ensure uniqueness by the ID (if specified), otherwise all elements
// are assumed to be unique.
uniqBy(
mediaArray,
(media) => media.getID() ?? media,
),
uniqBy(mediaArray, (media) => media.getID() ?? media),
// Sort all items leading with the most recent.
(media) => media.getStartTime(),
@@ -315,9 +312,15 @@ export class CameraManager {
result = await engine.getRecordingSegments(hass, this._cameras, query);
}
// The engine may independently cached the results. Respect that in our
// debug logging.
if (result?.cached) {
queryCachedCount++;
}
if (result) {
if (result.expiry) {
this._requestCache.set(query, result, result.expiry);
this._requestCache.set(query, { ...result, cached: true }, result.expiry);
}
results.set(query, result as QueryReturnType<QT>);
}
+1
View File
@@ -45,6 +45,7 @@ export interface QueryResults {
type: QueryResultsType;
engine: Engine;
expiry?: Date;
cached?: boolean;
}
export type QueryReturnType<QT> = QT extends EventQuery