~comcloudway/melon

70504a9f71594469e0418e3a47efcc3c3928d3b3 — Jakob Meier a month ago c57b103
Cache feed item thumbnail

This should significantly increase the refresh speed,
especially when reordering plalist items
1 files changed, 13 insertions(+), 0 deletions(-)

M melon/widgets/feeditem.py
M melon/widgets/feeditem.py => melon/widgets/feeditem.py +13 -0
@@ 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):