[gnome-music/wip/mschraal/texturecache-memory-size-improvements: 6/9] texturecache: Add timing information




commit dfd09adfc26e3805241f6c379cc67596180966a2
Author: Marinus Schraal <mschraal gnome org>
Date:   Tue Apr 12 15:51:15 2022 +0200

    texturecache: Add timing information
    
    Keep track of when a URI was last retrieved in the cache.

 gnomemusic/texturecache.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/texturecache.py b/gnomemusic/texturecache.py
index bd59fc4c3..e4b1a22c6 100644
--- a/gnomemusic/texturecache.py
+++ b/gnomemusic/texturecache.py
@@ -25,7 +25,7 @@
 from __future__ import annotations
 from enum import IntEnum
 from typing import Dict, Optional, Tuple, Union
-import typing
+import time, typing
 
 from gi.repository import GObject, Gdk
 
@@ -65,7 +65,7 @@ class TextureCache(GObject.GObject):
     _async_queue = AsyncQueue("TextureCache")
 
     _textures: Dict[str, Tuple[
-        TextureCache.LoadingState, Optional[Gdk.Texture]]] = {}
+        TextureCache.LoadingState, float, Optional[Gdk.Texture]]] = {}
 
     def __init__(self) -> None:
         """Initialize Texturecache
@@ -93,11 +93,13 @@ class TextureCache(GObject.GObject):
         self.clear_pending_lookup_callback()
 
         if uri in TextureCache._textures.keys():
-            state, texture = TextureCache._textures[uri]
+            state, _, texture = TextureCache._textures[uri]
             if state in [
                     TextureCache.LoadingState.AVAILABLE,
                     TextureCache.LoadingState.UNAVAILABLE]:
                 self.emit("texture", texture)
+                TextureCache._textures[self._uri] = (
+                    state, time.time(), texture)
                 return
 
         self._art_loader = MediaArtLoader()
@@ -112,6 +114,6 @@ class TextureCache(GObject.GObject):
         else:
             state = TextureCache.LoadingState.UNAVAILABLE
 
-        TextureCache._textures[self._uri] = (state, texture)
+        TextureCache._textures[self._uri] = (state, time.time(), texture)
 
         self.emit("texture", texture)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]