Merge lp:~ahayzen/music-app/remix-fix-playlists-1392022 into lp:music-app/remix

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 737
Merged at revision: 737
Proposed branch: lp:~ahayzen/music-app/remix-fix-playlists-1392022
Merge into: lp:music-app/remix
Diff against target: 83 lines (+37/-16)
1 file modified
playlists.js (+37/-16)
To merge this branch: bzr merge lp:~ahayzen/music-app/remix-fix-playlists-1392022
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Victor Thompson Approve
Review via email: mp+241626@code.launchpad.net

Commit message

* Remove erroneous tracks from the playlist

Description of the change

* Remove erroneous tracks from the playlist

This removes any tracks that are no longer in the playlist.

TESTING:
1) Make a playlist with multiple tracks eg 1, 2, 3, 2, 3
2) Optionally close the app
3) Delete track 2 from the device
4) Start the app if you closed it
5) Open the playlist and only tracks 1, 3, 3 should be shown.
Note the covers should be correct on the playlists tab but the count will be incorrect until a restart.

To post a comment you must log in.
Revision history for this message
Victor Thompson (vthompson) wrote :

LGTM! Good work with the quick turnaround!

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'playlists.js'
--- playlists.js 2014-11-10 02:55:32 +0000
+++ playlists.js 2014-11-12 21:21:22 +0000
@@ -202,6 +202,8 @@
202 var db = getPlaylistDatabase()202 var db = getPlaylistDatabase()
203 var res = []203 var res = []
204204
205 var erroneousTracks = [];
206
205 try {207 try {
206 db.transaction(function (tx) {208 db.transaction(function (tx) {
207 var rs = tx.executeSql('SELECT * FROM track WHERE playlist=?;',209 var rs = tx.executeSql('SELECT * FROM track WHERE playlist=?;',
@@ -209,20 +211,37 @@
209 for (var j = 0; j < rs.rows.length; j++) {211 for (var j = 0; j < rs.rows.length; j++) {
210 var dbItem = rs.rows.item(j)212 var dbItem = rs.rows.item(j)
211213
212 res.push({214 if (musicStore.lookup(dbItem.filename) === null) {
213 i: dbItem.i,215 erroneousTracks.push(dbItem.i);
214 filename: dbItem.filename,216 } else {
215 title: dbItem.title,217 res.push({
216 author: dbItem.author,218 i: dbItem.i,
217 album: dbItem.album,219 filename: dbItem.filename,
218 art: musicStore.lookup(dbItem.filename).art220 title: dbItem.title,
219 })221 author: dbItem.author,
220 }222 album: dbItem.album,
223 art: musicStore.lookup(dbItem.filename).art
224 })
225 }
226 }
227
228 // remove bad tracks
229 for (var j=0; j < erroneousTracks.length; j++) {
230 console.debug("Remove", erroneousTracks[j], "from playlist", playlist);
231 res = tx.executeSql('DELETE FROM track WHERE playlist=? AND i=?;',
232 [playlist, erroneousTracks[j]]).rowsAffected > 0
233 }
234
235 reorder(playlist, "remove", tx)
221 })236 })
222 } catch (e) {237 } catch (e) {
223 return []238 return []
224 }239 }
225240
241 if (erroneousTracks.length > 0) { // reget data as indexes are out of sync
242 res = getPlaylistTracks(playlist)
243 }
244
226 return res245 return res
227}246}
228247
@@ -260,14 +279,16 @@
260279
261 for (var i = 0; i < rs.rows.length280 for (var i = 0; i < rs.rows.length
262 && i < (max || rs.rows.length); i++) {281 && i < (max || rs.rows.length); i++) {
263 var row = {282 if (musicStore.lookup(rs.rows.item(i).filename) !== null) {
264 author: rs.rows.item(i).author,283 var row = {
265 album: rs.rows.item(i).album,284 author: rs.rows.item(i).author,
266 art: musicStore.lookup(rs.rows.item(i).filename).art285 album: rs.rows.item(i).album,
267 }286 art: musicStore.lookup(rs.rows.item(i).filename).art
287 }
268288
269 if (find(res, row) === null) {289 if (find(res, row) === null) {
270 res.push(row)290 res.push(row)
291 }
271 }292 }
272 }293 }
273 })294 })

Subscribers

People subscribed via source and target branches