@@ 14,6 14,9 @@ from unidecode import unidecode
from gettext import gettext as _
from melon.utils import pass_me, many
+# dictionary used to cache preview textures
+# [url]: texture
+preview_cache = {}
class AdaptiveFeedItem(Adw.ActionRow):
"""
@@ 109,9 112,14 @@ class AdaptiveFeedItem(Adw.ActionRow):
queue.add(self.update_avatar, thumb_url)
def update_avatar(self, url):
+ if url in preview_cache:
+ texture = preview_cache[url]
+ GLib.idle_add(self.complete_avatar, texture)
+ return
pixbuf = pixbuf_from_url(url)
if not pixbuf is None:
texture = Gdk.Texture.new_for_pixbuf(pixbuf)
+ preview_cache[url] = texture
GLib.idle_add(self.complete_avatar, texture)
def complete_avatar(self, texture):
@@ 207,9 215,14 @@ class AdaptivePlaylistFeedItem(Adw.ActionRow):
queue.add(self.update_avatar, playlist.inner.thumbnail)
def update_avatar(self, url):
+ if url in preview_cache:
+ texture = preview_cache[url]
+ GLib.idle_add(self.complete_avatar, texture)
+ return
pixbuf = pixbuf_from_url(url)
if not pixbuf is None:
texture = Gdk.Texture.new_for_pixbuf(pixbuf)
+ preview_cache[url] = texture
GLib.idle_add(self.complete_avatar, texture)
def complete_avatar(self, texture):