From 70504a9f71594469e0418e3a47efcc3c3928d3b3 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 14 Aug 2024 08:36:38 +0200 Subject: [PATCH] Cache feed item thumbnail This should significantly increase the refresh speed, especially when reordering plalist items --- melon/widgets/feeditem.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/melon/widgets/feeditem.py b/melon/widgets/feeditem.py index 09457a8..7678028 100644 --- a/melon/widgets/feeditem.py +++ b/melon/widgets/feeditem.py @@ -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): -- 2.38.5