From e1a6fc09afc088dcb67263ed5923f5be41c32c31 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sun, 25 May 2025 21:38:37 -0500 Subject: use lazy caching texture list to limit number of images loaded at one time --- immich.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'immich.py') diff --git a/immich.py b/immich.py index 63e6f63..e73b34e 100644 --- a/immich.py +++ b/immich.py @@ -1,5 +1,6 @@ import requests from io import BytesIO +from queue import Queue from texture import ImageTexture @@ -8,6 +9,7 @@ class ImmichConnector: def __init__(self, server_url, api_key): self.server_url = server_url.removesuffix("/") self.api_key = api_key + self.texture_load_queue = Queue() def _request(self, endpoint): return requests.get(f"{self.server_url}/api/{endpoint}", headers={ "x-api-key": self.api_key }) @@ -34,12 +36,14 @@ class ImmichConnector: mimetype = response.headers.get("Content-Type") return image_data, mimetype - def load_texture(self, pd, key, exif=None, size="preview"): - image_data, _ = self.load_image(key, size) - it = ImageTexture(image_data, exif) - pd.textures.append(it) - print(f"Loaded image {key}") - - def idle(self, pd): - for asset in self.load_album_assets("bac029a5-972b-4519-bce0-a0d74add3969"): - self.load_texture(pd, asset["id"], asset["exifInfo"]) + def load_texture_async(self, texture_list, image_texture): + self.texture_load_queue.put((texture_list, image_texture)) + + def idle(self): + size = "preview" # TODO + while True: + texture_list, image_texture = self.texture_load_queue.get() + if not texture_list.index_in_cache_range(image_texture.asset_index): + continue # Texture was never loaded so it doesn't need to be free'd + image_data, _ = self.load_image(image_texture.asset_key, size) + image_texture.initialize(image_data) -- cgit v1.2.3