List Update

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: List Update

Re: List Update

by serendip1959 » Sat Apr 04, 2020 12:58 pm

Doh! Right in front of me. Thanks, don't know how many times I looked at that. Great tip about fast for each.

Re: List Update

by Ludek » Sat Apr 04, 2020 12:24 pm

Hi,
I guess that the problem is that commitAsync is not property, but method.

So use itm.commitAsync(); instead!

Also I think that the 'async' is not needed, you can use just 'function' or the arrow notation, i.e. (itm) => {.....
And if you want to make the processing faster for large lists then use fastForEach from mminit.js

Code: Select all

fastForEach(list, function (itm) { ....
just note that in the fast variant the itm object is just 'temporal JS object that is used for binding all tracks', i.e. you should avoid using it outside of function(itm) {... body.

Re: List Update

by serendip1959 » Sat Apr 04, 2020 10:18 am

Take a look at this. I am using 2238.

Code: Select all

var list;
            list = app.db.getTracklist("SELECT * FROM Songs WHERE Artist = '" + artist + "' AND Album = '" + album + "' AND SongTitle = '" + track + "'", -1)
            list.whenLoaded().then(async function () {

                if (list.count === 0) {
                    return;
                }

                var changed = false;
                list.beginUpdate;
                list.forEach(async function (itm) {
                    itm.beginUpdate;
                    if (played > itm.playCounter && played > 0) {
                        changed = true;
                        itm.playCounter = itm.playCounter + (played - itm.playCounter);
                    }
                    if (playedDate > itm.lastTimePlayed) {
                        changed = true;
                        itm.lastTimePlayed = playedDate;
                    }
                    if (changed === true) {
                        itm.commitAsync;
                        changed = false;
                    };
                    itm.endUpdate;
                });
                list.endUpdate;

            });
Thanks. Is there another way of finding a specific track?

Re: List Update

by Ludek » Sat Apr 04, 2020 9:46 am

Strange, as we use this function regularly in the native code and it works.

e.g. see tracksToUpdate.commitAsync(); in the dlgAutoTagFromFilename.js :
https://www.dropbox.com/s/6ek9t53uyfzro ... 7.png?dl=0

Just tested it and it updated the tracks metadata to the database and tags without an issue. Also tested with app.db.getTracklist and it also worked.

Are you using the newest build 2238 ?
Maybe if you could share a sample script that I could try and debug?

Re: List Update

by serendip1959 » Sat Apr 04, 2020 7:48 am

I am updating play count and last played.

I have tried both track.commitAsync and list.commitAsync without success. I also tried creating an empty track list interface and then addList with the same result. The main window updates but nothing is written to the database.

Re: List Update

by Ludek » Sat Apr 04, 2020 6:29 am

Which changes are you referring? Based on documentation it "Commits all tracks into database and tag"
i.e. if you e.g. change a property (say title) for the tracks within the list then the changes are commited to the DB and tag.
It is similar like if you would call commitAsync for each track individually.

Or are you referring some other changes?

List Update

by serendip1959 » Sat Apr 04, 2020 3:13 am

If I call:

list = app.db.getTracklist(<SQL SELECT>, -1)
list.whenLoaded().then(function () {

A list is returned. but if I edit the list and then call

list.commitAsync;

The main window updates with the changes, but they are not committed to the database. When MM is reloaded the changes are undone.

Top