From f39140f6efa8d757fafb09ca6404cbcf5aa3c851 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sat, 28 Jan 2023 09:19:42 -0800 Subject: [PATCH] smaller batch sizes to make search results appear faster --- ui/widgets/albumgrid.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ui/widgets/albumgrid.go b/ui/widgets/albumgrid.go index ba1d6e0..194692b 100644 --- a/ui/widgets/albumgrid.go +++ b/ui/widgets/albumgrid.go @@ -11,6 +11,8 @@ import ( "github.com/dweymouth/go-subsonic" ) +const albumFetchBatchSize = 6 + type ImageFetcher interface { GetAlbumThumbnailFromCache(string) (image.Image, bool) GetAlbumThumbnail(string) (image.Image, error) @@ -181,15 +183,19 @@ func (a *AlbumGrid) fetchMoreAlbums(count int) { } a.fetching = true go func() { - albums := a.iter.NextN(count) - a.albums = append(a.albums, albums...) - if len(albums) < count { - a.done = true + n := 0 + for !a.done && n < count { + albums := a.iter.NextN(albumFetchBatchSize) + a.albums = append(a.albums, albums...) + if len(albums) < albumFetchBatchSize { + a.done = true + } + n += len(albums) + if len(albums) > 0 { + a.Refresh() + } } a.fetching = false - if len(albums) > 0 { - a.Refresh() - } }() }