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
1=== modified file 'meta-database.js'
2--- meta-database.js 2015-01-10 17:36:58 +0000
3+++ meta-database.js 2015-01-11 18:44:28 +0000
4@@ -22,12 +22,17 @@
5 return LocalStorage.openDatabaseSync("music-app-metadata", "1.0", "StorageDatabase", 1000000);
6 }
7
8-function createQueue() {
9- var db = getDatabase();
10- db.transaction(
11- function(tx) {
12- tx.executeSql("CREATE TABLE IF NOT EXISTS queue(ind INTEGER NOT NULL, filename TEXT)");
13- });
14+function createQueue(tx) {
15+ if (tx === undefined) {
16+ var db = getDatabase();
17+ db.transaction(
18+ function(tx) {
19+ createQueue(tx)
20+ }
21+ )
22+ } else {
23+ tx.executeSql("CREATE TABLE IF NOT EXISTS queue(ind INTEGER NOT NULL, filename TEXT)");
24+ }
25 }
26
27 function clearQueue() {
28@@ -39,11 +44,13 @@
29 });
30 }
31
32-function addQueueItem(ind,filename) {
33+function addQueueItem(filename) {
34 var db = getDatabase();
35 var res="";
36
37 db.transaction(function(tx) {
38+ var ind = getNextIndex(tx);
39+
40 var rs = tx.executeSql('INSERT OR REPLACE INTO queue (ind, filename) VALUES (?,?);', [ind, filename]);
41 if (rs.rowsAffected > 0) {
42 console.log("QUEUE add OK")
43@@ -56,10 +63,12 @@
44 );
45 }
46
47-function addQueueList(ind, items) {
48+function addQueueList(items) {
49 var db = getDatabase();
50
51 db.transaction(function(tx) {
52+ var ind = getNextIndex(tx);
53+
54 for (var i = 0; i < items.length; i++) {
55 tx.executeSql('INSERT OR REPLACE INTO queue (ind, filename) VALUES (?,?);', [i + ind, items[i].filename]);
56 }
57@@ -67,21 +76,34 @@
58 );
59 }
60
61+// Get the next index for the queue
62+function getNextIndex(tx) {
63+ var ind;
64+
65+ if (tx === undefined) {
66+ var db = getDatabase();
67+
68+ db.transaction(function(tx) {
69+ ind = getNextIndex(tx);
70+ });
71+ } else {
72+ var rs = tx.executeSql('SELECT MAX(ind) FROM queue')
73+ ind = isQueueEmpty(tx) ? 0 : rs.rows.item(0)["MAX(ind)"] + 1
74+ }
75+
76+ return ind;
77+}
78+
79 function moveQueueItem(from, to) {
80 var db = getDatabase();
81 var res="";
82
83 db.transaction(function(tx) {
84-
85- // Generate new index number if records exist, otherwise use 0
86- var rs = tx.executeSql('SELECT MAX(ind) FROM queue')
87-
88- var nextIndex = isNaN(rs.rows.item(0)["MAX(ind)"]) ? 0 : rs.rows.item(
89- 0)["MAX(ind)"] + 1
90-
91+ // Track to move put as -1 for now
92 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
93- [nextIndex, from])
94+ [-1, from])
95
96+ // Shuffle tracks inbetween from->to
97 if (from > to) {
98 for (var i = from-1; i >= to; i--) {
99 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
100@@ -94,8 +116,9 @@
101 }
102 }
103
104+ // Switch moving track to its new position
105 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
106- [to, nextIndex])
107+ [to, -1])
108
109 })
110 }
111@@ -109,8 +132,8 @@
112
113 var rs = tx.executeSql('SELECT MAX(ind) FROM queue')
114
115- var lastIndex = isNaN(rs.rows.item(0)["MAX(ind)"]) ? 0 : rs.rows.item(
116- 0)["MAX(ind)"]
117+ var lastIndex = isQueueEmpty() ? 0 : rs.rows.item(0)["MAX(ind)"]
118+
119 for(var i = ind+1; i <= lastIndex; i++) {
120 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
121 [i-1, i])
122@@ -125,18 +148,19 @@
123 function removeQueueList(list)
124 {
125 var db = getDatabase()
126+ var i;
127 var res = false
128
129 db.transaction(function (tx) {
130 // Remove all the deleted indexes
131- for (var ind in list) {
132- tx.executeSql('DELETE FROM queue WHERE ind=?;', [ind])
133+ for (i=0; i < list.length; i++) {
134+ tx.executeSql('DELETE FROM queue WHERE ind=?;', [list[i]])
135 }
136
137 // Rebuild queue in order
138- var rs = tx.executeSql('SELECT ind FROM queue')
139+ var rs = tx.executeSql('SELECT ind FROM queue ORDER BY ind ASC')
140
141- for (var i=0; i < rs.rows.length; i++) {
142+ for (i=0; i < rs.rows.length; i++) {
143 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
144 [i, rs.rows.item(i).ind])
145 }
146@@ -160,16 +184,23 @@
147 return res;
148 }
149
150-function isQueueEmpty() {
151- var db = getDatabase();
152- var res = 0;
153-
154- db.transaction( function(tx) {
155- createQueue();
156+function isQueueEmpty(tx) {
157+ var empty = false;
158+
159+ if (tx === undefined) {
160+ var db = getDatabase();
161+ var res = 0;
162+
163+ db.transaction( function(tx) {
164+ empty = isQueueEmpty(tx)
165+ });
166+ } else {
167+ createQueue(tx);
168 var rs = tx.executeSql("SELECT count(*) as value FROM queue")
169- res = rs.rows.item(0).value === 0
170- });
171- return res
172+ empty = rs.rows.item(0).value === 0
173+ }
174+
175+ return empty
176 }
177
178 function createRecent() {
179
180=== modified file 'music-app.qml'
181--- music-app.qml 2015-01-11 17:04:55 +0000
182+++ music-app.qml 2015-01-11 18:44:28 +0000
183@@ -606,7 +606,6 @@
184 }
185
186 var items = []
187- var previousQueueSize = trackQueue.model.count
188
189 for (var i=0; i < model.rowCount; i++) {
190 items.push(model.get(i, model.RoleModelData))
191@@ -615,7 +614,7 @@
192 }
193
194 // Add model to queue storage
195- Library.addQueueList(previousQueueSize, items);
196+ Library.addQueueList(items);
197 }
198
199 // Converts an duration in ms to a formated string ("minutes:seconds")
200@@ -803,7 +802,7 @@
201 function append(listElement)
202 {
203 model.append(makeDict(listElement))
204- Library.addQueueItem(trackQueue.model.count, listElement.filename)
205+ Library.addQueueItem(listElement.filename)
206 }
207
208 function clear()

Subscribers

People subscribed via source and target branches