Cache some folder listings for quicker browsing

Suggestions/requests/ideas for RuneAudio core features and functions

Cache some folder listings for quicker browsing

Postby waves » 13 Dec 2015, 13:34

AFAIK every time the user navigates to a folder in the library RuneAudio queries MPD and generates a fresh file/folder list and that results in delays/long loading time for folders with a lot of files/subfolders. For example on my Android one folder with a lot of songs in it takes around 6 seconds to load every time, even if I only navigate out of it and navigate back.

Will the next major RuneAudio release cache such file/folder lists for quicker loading? A cached listing could be useful also for browsing by album, artist and genre.
waves
 
Posts: 125
Joined: 31 Dec 2014, 10:33

Re: Cache some folder listings for quicker browsing

Postby waves » 14 Dec 2015, 18:03

I tested a bit and was able to achieve at least partial caching of the slowest loading folder in my library. Let us call that folder "slowfolder" from now on.

The file to edit is runeui.js

First some background. When you navigate to the slowfolder (or any other folder) in the library
runeui.js by default does these things every time:
1 call the function getDB(options) which does a
2 $.post call to MPD to retrieve data about the folder contents. The returned data is next
3 put into the function populateDB(options)
4 which generates the html content for that library page.

We can speed things with these changes to runeui.js
1 near the top declare an empty variable to later on put the cached content in
2 edit populateDB(options) tot save the content to a cache variable when our slowfolder is loaded the first time and thereafter reuse that content each time the folder is opened.
3 edit getDB(options) to similarly only read data for the slowfolder from MPD the first time and thereafter resuse the cached content.

Before you jump in keep in mind that this is only partial caching because the first load of the slowfolder will not be any faster than before. And every time the browser tab is reloaded or closed and reopened the next load of slowfolder will be slow again.

A better method could generate the content for the slowfolder in the background when RuneAudio boots and then save it to a variable in php that is stable between browser reloads and is available on all devices. I'll be delighted if someone comes up with something like that.

But for now this is what I've got

Below the line
Code: Select all
// Global GUI Array

add these lines
Code: Select all
var slowcache;   
var slowfolder = "USB/one folder/the slow folder"

Edit the slowfolder string to match the folder you want to enable cache for. I think the structure is <mountpoint root name>/<subfolder name>/<slow folder name>

Inside the large getDB(options) function find the line
Code: Select all
else if (cmd === 'browse') {

and add this directly below it
Code: Select all
            if ((path == slowfolder && slowcache)
             populateDB({
                    data: "",
                    path: path,
                    uplevel: uplevel
                });
            else

Make sure there is no empty line between that final else and the already existing content that comes next in the file. In other words it should look like this
Code: Select all
            if ((path == slowfolder && slowcache)
             populateDB({
                    data: "",
                    path: path,
                    uplevel: uplevel
                });
            else
            $.post('/db/?cmd=browse', { 'path': path, 'browsemode': GUI.browsemode }, function(data) {
                populateDB({
                    data: data,
                    path: path,
                    uplevel: uplevel
                });
            }, 'json');


Finally inside the large function populateDB(options) find the line that starts with
Code: Select all
$('#db-search-results').removeClass('hide')

below it you see this
Code: Select all
            }
            for (i = 0; (row = data[i]); i += 1) {
                content += parseResponse({
                    inputArr: row,
                    respType: 'db',
                    i: i,
                    inpath: path
                });
            }

Which should be changed into
Code: Select all
            }
            if (path == slowfolder && slowcache)
             content = slowcache
           else
           {
            for (i = 0; (row = data[i]); i += 1) {
                content += parseResponse({
                    inputArr: row,
                    respType: 'db',
                    i: i,
                    inpath: path
                });
            }
            if (path == slowfolder && !slowcache)
             slowcache = content
           }

That was all the edits. Now save runeui.js then copy its contents into http://gpbmike.github.io/refresh-sf/ , click "Javascript", put the minified code on the clipboard , open runeui.min.js and replace everything in it with the clipboard text. Save. That is it.

Edit: fixed a typo in the code.
waves
 
Posts: 125
Joined: 31 Dec 2014, 10:33

support RuneAudio Donate with PayPal


Return to Feature request

Who is online

Users browsing this forum: No registered users and 1 guest