Skip to content

Commit

Permalink
- Cache thumbnails in gtk2-youtube-viewer.
Browse files Browse the repository at this point in the history
Provides better performance for the "Previous/Next results" feature.
  • Loading branch information
trizen committed Sep 12, 2020
1 parent cbe82fa commit fe8ce06
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bin/gtk2-youtube-viewer
Expand Up @@ -2390,6 +2390,14 @@ sub get_pixbuf_thumbnail {
$xsize //= 160;
$ysize //= 90;

state %cache;

my $key = "$url $xsize $ysize";

if (exists $cache{$key}) {
return $cache{$key};
}

my $thumbnail = $yv_obj->lwp_get($url, simple => 1);

my $pixbuf;
Expand All @@ -2412,6 +2420,10 @@ sub get_pixbuf_thumbnail {
};
}

if (defined($pixbuf)) {
$cache{$key} = $pixbuf;
}

$pixbuf //= $default_thumb;

return $pixbuf;
Expand Down

0 comments on commit fe8ce06

Please sign in to comment.