Fix substantial performance issue with thumbnails.

This commit is contained in:
Dermot Duffy
2022-09-22 17:44:44 -07:00
parent b9b539bf72
commit c910b5d2a4
3 changed files with 70 additions and 23 deletions
+14 -10
View File
@@ -55,19 +55,23 @@ export const createFetchThumbnailTask = (
host: ReactiveControllerHost,
getHASS: () => HomeAssistant | undefined,
getThumbnailURL: () => string | undefined,
autoRun = true,
): Task<FetchThumbnailTaskArgs, string | null> => {
return new Task(
host,
async ([haveHASS, thumbnailURL]: FetchThumbnailTaskArgs): Promise<
string | null
> => {
const hass = getHASS();
if (!haveHASS || !hass || !thumbnailURL) {
return null;
}
return fetchThumbnail(hass, thumbnailURL);
{
// Do not re-run the task if hass changes, unless it was previously undefined.
args: (): FetchThumbnailTaskArgs => [!!getHASS(), getThumbnailURL()],
task: async ([haveHASS, thumbnailURL]: FetchThumbnailTaskArgs): Promise<
string | null
> => {
const hass = getHASS();
if (!haveHASS || !hass || !thumbnailURL) {
return null;
}
return fetchThumbnail(hass, thumbnailURL);
},
autoRun: autoRun,
},
// Do not re-run the task if hass changes, unless it was previously undefined.
(): FetchThumbnailTaskArgs => [!!getHASS(), getThumbnailURL()],
);
};