Merge lp:~ahayzen/music-app/fix-1407814-save-order-correctly into lp:music-app/remix

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 777
Merged at revision: 778
Proposed branch: lp:~ahayzen/music-app/fix-1407814-save-order-correctly
Merge into: lp:music-app/remix
Diff against target: 208 lines (+65/-35)
2 files modified
meta-database.js (+63/-32)
music-app.qml (+2/-3)
To merge this branch: bzr merge lp:~ahayzen/music-app/fix-1407814-save-order-correctly
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+245615@code.launchpad.net

Commit message

* Fix for incorrect saving of queue

Description of the change

* Fix for incorrect saving of queue

The code used to start at index number 1, this has now been fixed so it starts at 0, which caused reordering/removals later on to break.

There is the potential that the queue may already be corrupted (or start at 1 instead of 0), this will remain 'corrupt' until the user clears the queue or selects to play an album (which clears the queue first) etc.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

The refactor to get the next index inside the request is a good idea, nice work. This does seem to fix the problem. I'll try to do more testing tonight/tomorrow night.

772. By Andrew Hayzen

* Ensure that getNextIndex() is done in 1 transaction

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

This doesn't seem to fix lp:1407840. Also, currently adding an album (Step #2 in the bug) at first caused the items in the queue to not be what was expected [1]. The first 3 songs in that screenshot should not be there and the currently playing item should still be what is in the toolbar.

[1] http://i.imgur.com/VArr7Ou.png

review: Needs Fixing
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

This mp [2] fixes various issues todo with remove i propose to hold this mp until that has landed as this may then resolve bug 1407840.

2 - https://code.launchpad.net/~andrew-hayzen/music-app/fix-1409186-queue-delete-refactor/+merge/246036

773. By Andrew Hayzen

* Merge of trunk

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
774. By Andrew Hayzen

* Merge of trunk

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
775. By Andrew Hayzen

* Merge of trunk

776. By Andrew Hayzen

* Fix for wrong use of for in, use for i=0; i < length; i++ instead

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
777. By Andrew Hayzen

* Add ORDER BY to SELECT when resorting the indexes in a removeQueueList
* Use -1 as the temporary index for reorder instead of the calc'd max

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

LGTM! Queue saving is working fine now. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'meta-database.js'
--- meta-database.js 2015-01-10 17:36:58 +0000
+++ meta-database.js 2015-01-11 18:44:28 +0000
@@ -22,12 +22,17 @@
22 return LocalStorage.openDatabaseSync("music-app-metadata", "1.0", "StorageDatabase", 1000000);22 return LocalStorage.openDatabaseSync("music-app-metadata", "1.0", "StorageDatabase", 1000000);
23}23}
2424
25function createQueue() {25function createQueue(tx) {
26 var db = getDatabase();26 if (tx === undefined) {
27 db.transaction(27 var db = getDatabase();
28 function(tx) {28 db.transaction(
29 tx.executeSql("CREATE TABLE IF NOT EXISTS queue(ind INTEGER NOT NULL, filename TEXT)");29 function(tx) {
30 });30 createQueue(tx)
31 }
32 )
33 } else {
34 tx.executeSql("CREATE TABLE IF NOT EXISTS queue(ind INTEGER NOT NULL, filename TEXT)");
35 }
31}36}
3237
33function clearQueue() {38function clearQueue() {
@@ -39,11 +44,13 @@
39 });44 });
40}45}
4146
42function addQueueItem(ind,filename) {47function addQueueItem(filename) {
43 var db = getDatabase();48 var db = getDatabase();
44 var res="";49 var res="";
4550
46 db.transaction(function(tx) {51 db.transaction(function(tx) {
52 var ind = getNextIndex(tx);
53
47 var rs = tx.executeSql('INSERT OR REPLACE INTO queue (ind, filename) VALUES (?,?);', [ind, filename]);54 var rs = tx.executeSql('INSERT OR REPLACE INTO queue (ind, filename) VALUES (?,?);', [ind, filename]);
48 if (rs.rowsAffected > 0) {55 if (rs.rowsAffected > 0) {
49 console.log("QUEUE add OK")56 console.log("QUEUE add OK")
@@ -56,10 +63,12 @@
56 );63 );
57}64}
5865
59function addQueueList(ind, items) {66function addQueueList(items) {
60 var db = getDatabase();67 var db = getDatabase();
6168
62 db.transaction(function(tx) {69 db.transaction(function(tx) {
70 var ind = getNextIndex(tx);
71
63 for (var i = 0; i < items.length; i++) {72 for (var i = 0; i < items.length; i++) {
64 tx.executeSql('INSERT OR REPLACE INTO queue (ind, filename) VALUES (?,?);', [i + ind, items[i].filename]);73 tx.executeSql('INSERT OR REPLACE INTO queue (ind, filename) VALUES (?,?);', [i + ind, items[i].filename]);
65 }74 }
@@ -67,21 +76,34 @@
67 );76 );
68}77}
6978
79// Get the next index for the queue
80function getNextIndex(tx) {
81 var ind;
82
83 if (tx === undefined) {
84 var db = getDatabase();
85
86 db.transaction(function(tx) {
87 ind = getNextIndex(tx);
88 });
89 } else {
90 var rs = tx.executeSql('SELECT MAX(ind) FROM queue')
91 ind = isQueueEmpty(tx) ? 0 : rs.rows.item(0)["MAX(ind)"] + 1
92 }
93
94 return ind;
95}
96
70function moveQueueItem(from, to) {97function moveQueueItem(from, to) {
71 var db = getDatabase();98 var db = getDatabase();
72 var res="";99 var res="";
73100
74 db.transaction(function(tx) {101 db.transaction(function(tx) {
75102 // Track to move put as -1 for now
76 // Generate new index number if records exist, otherwise use 0
77 var rs = tx.executeSql('SELECT MAX(ind) FROM queue')
78
79 var nextIndex = isNaN(rs.rows.item(0)["MAX(ind)"]) ? 0 : rs.rows.item(
80 0)["MAX(ind)"] + 1
81
82 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',103 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
83 [nextIndex, from])104 [-1, from])
84105
106 // Shuffle tracks inbetween from->to
85 if (from > to) {107 if (from > to) {
86 for (var i = from-1; i >= to; i--) {108 for (var i = from-1; i >= to; i--) {
87 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',109 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
@@ -94,8 +116,9 @@
94 }116 }
95 }117 }
96118
119 // Switch moving track to its new position
97 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',120 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
98 [to, nextIndex])121 [to, -1])
99122
100 })123 })
101}124}
@@ -109,8 +132,8 @@
109132
110 var rs = tx.executeSql('SELECT MAX(ind) FROM queue')133 var rs = tx.executeSql('SELECT MAX(ind) FROM queue')
111134
112 var lastIndex = isNaN(rs.rows.item(0)["MAX(ind)"]) ? 0 : rs.rows.item(135 var lastIndex = isQueueEmpty() ? 0 : rs.rows.item(0)["MAX(ind)"]
113 0)["MAX(ind)"]136
114 for(var i = ind+1; i <= lastIndex; i++) {137 for(var i = ind+1; i <= lastIndex; i++) {
115 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',138 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
116 [i-1, i])139 [i-1, i])
@@ -125,18 +148,19 @@
125function removeQueueList(list)148function removeQueueList(list)
126{149{
127 var db = getDatabase()150 var db = getDatabase()
151 var i;
128 var res = false152 var res = false
129153
130 db.transaction(function (tx) {154 db.transaction(function (tx) {
131 // Remove all the deleted indexes155 // Remove all the deleted indexes
132 for (var ind in list) {156 for (i=0; i < list.length; i++) {
133 tx.executeSql('DELETE FROM queue WHERE ind=?;', [ind])157 tx.executeSql('DELETE FROM queue WHERE ind=?;', [list[i]])
134 }158 }
135159
136 // Rebuild queue in order160 // Rebuild queue in order
137 var rs = tx.executeSql('SELECT ind FROM queue')161 var rs = tx.executeSql('SELECT ind FROM queue ORDER BY ind ASC')
138162
139 for (var i=0; i < rs.rows.length; i++) {163 for (i=0; i < rs.rows.length; i++) {
140 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',164 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
141 [i, rs.rows.item(i).ind])165 [i, rs.rows.item(i).ind])
142 }166 }
@@ -160,16 +184,23 @@
160 return res;184 return res;
161}185}
162186
163function isQueueEmpty() {187function isQueueEmpty(tx) {
164 var db = getDatabase();188 var empty = false;
165 var res = 0;189
166190 if (tx === undefined) {
167 db.transaction( function(tx) {191 var db = getDatabase();
168 createQueue();192 var res = 0;
193
194 db.transaction( function(tx) {
195 empty = isQueueEmpty(tx)
196 });
197 } else {
198 createQueue(tx);
169 var rs = tx.executeSql("SELECT count(*) as value FROM queue")199 var rs = tx.executeSql("SELECT count(*) as value FROM queue")
170 res = rs.rows.item(0).value === 0200 empty = rs.rows.item(0).value === 0
171 });201 }
172 return res202
203 return empty
173}204}
174205
175function createRecent() {206function createRecent() {
176207
=== modified file 'music-app.qml'
--- music-app.qml 2015-01-11 17:04:55 +0000
+++ music-app.qml 2015-01-11 18:44:28 +0000
@@ -606,7 +606,6 @@
606 }606 }
607607
608 var items = []608 var items = []
609 var previousQueueSize = trackQueue.model.count
610609
611 for (var i=0; i < model.rowCount; i++) {610 for (var i=0; i < model.rowCount; i++) {
612 items.push(model.get(i, model.RoleModelData))611 items.push(model.get(i, model.RoleModelData))
@@ -615,7 +614,7 @@
615 }614 }
616615
617 // Add model to queue storage616 // Add model to queue storage
618 Library.addQueueList(previousQueueSize, items);617 Library.addQueueList(items);
619 }618 }
620619
621 // Converts an duration in ms to a formated string ("minutes:seconds")620 // Converts an duration in ms to a formated string ("minutes:seconds")
@@ -803,7 +802,7 @@
803 function append(listElement)802 function append(listElement)
804 {803 {
805 model.append(makeDict(listElement))804 model.append(makeDict(listElement))
806 Library.addQueueItem(trackQueue.model.count, listElement.filename)805 Library.addQueueItem(listElement.filename)
807 }806 }
808807
809 function clear()808 function clear()

Subscribers

People subscribed via source and target branches