From 9d756e2760a0926aa416b22e276c4a5b2685e84e Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Sat, 21 Jul 2007 17:35:19 +0000 Subject: Queue song statistical data to the tagcache system and update entirely in background. Fixes ratings disappearing or not saving in the DB at all. Fixes also UI delay when stopping playback and new statistics are committed to DB. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13955 a1c6a512-1295-4272-9138-f99709370657 --- apps/tagtree.c | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) (limited to 'apps/tagtree.c') diff --git a/apps/tagtree.c b/apps/tagtree.c index 03673fc653..271f30ffa8 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -624,9 +624,14 @@ static void tagtree_buffer_event(struct mp3entry *id3, bool last_track) } id3->playcount = tagcache_get_numeric(&tcs, tag_playcount); - if(!id3->rating) id3->rating = tagcache_get_numeric(&tcs, tag_rating); + if (!id3->rating) + id3->rating = tagcache_get_numeric(&tcs, tag_rating); id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed); id3->score = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10; + id3->playtime = tagcache_get_numeric(&tcs, tag_playtime); + + /* Store our tagcache index pointer. */ + id3->tagcache_idx = tcs.idx_id; tagcache_search_finish(&tcs); } @@ -635,7 +640,6 @@ static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track) { (void)last_track; long playcount; - long rating; long playtime; long lastplayed; @@ -646,55 +650,38 @@ static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track) return; } - /* Don't process unplayed tracks. */ - if (id3->elapsed == 0) + if (!id3->tagcache_idx) { - logf("not logging unplayed track"); + logf("No tagcache index pointer found"); return; } - if (!tagcache_find_index(&tcs, id3->path)) + /* Don't process unplayed tracks. */ + if (id3->elapsed == 0) { - logf("tc stat: not found: %s", id3->path); + logf("not logging unplayed track"); return; } - playcount = tagcache_get_numeric(&tcs, tag_playcount); - playtime = tagcache_get_numeric(&tcs, tag_playtime); - lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed); - - playcount++; - - rating = (long) id3->rating; - + playcount = id3->playcount + 1; lastplayed = tagcache_increase_serial(); if (lastplayed < 0) { logf("incorrect tc serial:%ld", lastplayed); - tagcache_search_finish(&tcs); return; } /* Ignore the last 15s (crossfade etc.) */ - playtime += MIN(id3->length, id3->elapsed + 15 * 1000); + playtime = id3->playtime + MIN(id3->length, id3->elapsed + 15 * 1000); logf("ube:%s", id3->path); - logf("-> %d/%ld/%ld/%ld", last_track, playcount, rating, playtime); + logf("-> %d/%ld/%ld", last_track, playcount, playtime); logf("-> %ld/%ld/%ld", id3->elapsed, id3->length, MIN(id3->length, id3->elapsed + 15 * 1000)); - /* lastplayed not yet supported. */ - - if (!tagcache_modify_numeric_entry(&tcs, tag_playcount, playcount) - || !tagcache_modify_numeric_entry(&tcs, tag_rating, rating) - || !tagcache_modify_numeric_entry(&tcs, tag_playtime, playtime) - || !tagcache_modify_numeric_entry(&tcs, tag_lastplayed, lastplayed)) - { - logf("tc stat: modify failed!"); - tagcache_search_finish(&tcs); - return; - } - - tagcache_search_finish(&tcs); + /* Queue the updates to the tagcache system. */ + tagcache_update_numeric(id3->tagcache_idx, tag_playcount, playcount); + tagcache_update_numeric(id3->tagcache_idx, tag_playtime, playtime); + tagcache_update_numeric(id3->tagcache_idx, tag_lastplayed, lastplayed); } bool tagtree_export(void) -- cgit v1.2.3