perf: Variety of small type and performance fixes (#2367)

This commit is contained in:
Dermot Duffy
2026-02-22 15:02:14 -08:00
committed by GitHub
parent 0f8c758d38
commit 497e6e88a0
10 changed files with 82 additions and 53 deletions
+2 -4
View File
@@ -155,11 +155,9 @@ export const getReviewThumbnailURL = (
* Get generic review severity.
*/
export const getReviewSeverity = (severity: FrigateReviewSeverity): Severity => {
// Frigate severities: 'alert' -> 'high', 'detection' -> 'medium'.
if (severity === 'alert') {
return 'high';
}
if (severity === 'detection') {
return 'medium';
}
return 'low';
return 'medium';
};
+8 -12
View File
@@ -73,18 +73,14 @@ export class ConfigManager {
(hint ?? localize('error.invalid_configuration_no_hint')),
);
}
const config = advancedCameraCardConfigSchema.parse(
setProfiles(
inputConfig,
// The config is cloned here because Zod 4 returns shared constant
// defaults by reference. Since setProfiles() mutates the configuration
// in-place, those mutations would "pollute" the global defaults and break
// test isolation if we didn't use a fresh clone here.
copyConfig(parseResult.data),
parseResult.data.profiles,
),
// The config is cloned here because Zod 4 returns shared constant
// defaults by reference. Since setProfiles() mutates the configuration
// in-place, those mutations would "pollute" the global defaults and break
// test isolation if we didn't use a fresh clone here.
const config = setProfiles(
inputConfig,
copyConfig(parseResult.data),
parseResult.data.profiles,
);
this._rawConfig = inputConfig;
@@ -23,6 +23,7 @@ export class GalleryCoreController implements ReactiveController {
private _options: GalleryCoreOptions | null = null;
private _touchScrollYPosition: number | null = null;
private _observedSentinel: HTMLElement | null = null;
// Wheel / touch events may be voluminous, throttle extension calls.
private _throttledExtendUp = throttle(
@@ -99,14 +100,21 @@ export class GalleryCoreController implements ReactiveController {
this._host.removeEventListener('touchend', this._touchEndHandler);
this._resizeObserver.disconnect();
this._intersectionObserver.disconnect();
this._observedSentinel = null;
}
public hostUpdated(): void {
const sentinel = this._getSentintelBottom();
this._intersectionObserver.disconnect();
if (sentinel) {
this._intersectionObserver.observe(sentinel);
// Avoid redundant observer disconnect/reconnect on every Lit update cycle
// when the sentinel element hasn't changed.
if (sentinel !== this._observedSentinel) {
this._intersectionObserver.disconnect();
this._observedSentinel = sentinel;
if (sentinel) {
this._intersectionObserver.observe(sentinel);
}
}
}
+8 -7
View File
@@ -63,6 +63,8 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
private hass?: HomeAssistant;
private _videoRTC: VideoRTC | null = null;
private _mediaPlayerController = new VideoMediaPlayerController(
this,
() => this._getVideo(),
@@ -85,6 +87,7 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
}
disconnectedCallback(): void {
this._videoRTC = null;
this._message = null;
super.disconnectedCallback();
}
@@ -97,16 +100,12 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
}
}
private _getVideoRTC(): VideoRTC | null {
return (this.renderRoot?.querySelector('#webrtc') ?? null) as VideoRTC | null;
}
/**
* Get the underlying video player.
* @returns The player or `null` if not found.
*/
private _getVideo(): HTMLVideoElement | null {
return this._getVideoRTC()?.video ?? null;
return this._videoRTC?.video ?? null;
}
private async _getWebRTCCardElement(): Promise<CustomElementConstructor | undefined> {
@@ -196,7 +195,7 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
// Extract the video component after it has been rendered and generate the
// media load event.
this.updateComplete.then(() => {
const videoRTC = this._getVideoRTC();
this._videoRTC = this.renderRoot?.querySelector('#webrtc') ?? null;
const video = this._getVideo();
if (video) {
setControlsOnVideo(video, this.controls);
@@ -210,7 +209,9 @@ export class AdvancedCameraCardLiveWebRTCCard extends LitElement implements Medi
supportsPause: true,
hasAudio: mayHaveAudio(video),
},
...(videoRTC && { technology: getTechnologyForVideoRTC(videoRTC) }),
...(this._videoRTC && {
technology: getTechnologyForVideoRTC(this._videoRTC),
}),
});
};
video.onplay = () => dispatchMediaPlayEvent(this);