Merge lp:~ahayzen/music-app/remix-remember-queue-use-worker into lp:music-app/remix

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 699
Merged at revision: 706
Proposed branch: lp:~ahayzen/music-app/remix-remember-queue-use-worker
Merge into: lp:music-app/remix
Prerequisite: lp:~vthompson/music-app/remix-remember-queue
Diff against target: 345 lines (+145/-99)
6 files modified
LibraryListModel.qml (+10/-68)
Player.qml (+1/-1)
WorkerModelLoader.qml (+105/-0)
meta-database.js (+1/-2)
music-app.qml (+21/-20)
worker-library-loader.js (+7/-8)
To merge this branch: bzr merge lp:~ahayzen/music-app/remix-remember-queue-use-worker
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+239761@code.launchpad.net

Commit message

* Create generic WorkerModelLoader.qml
* Load queue at startup via WorkerScript

Description of the change

* Create generic WorkerModelLoader.qml
* Load queue at startup via WorkerScript

To post a comment you must log in.
693. By Andrew Hayzen

* Remove debugging lines

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

* Fix for setting of readonly source
* Fix for setting complete before syncing
* Sync after first item to ensure no empty state

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

* Pull of upstream

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

* Only set to complete once sync is complete

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

* Merge of upstream

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

* Merge with upstream

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

* Pull of upstream

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 LGTM and improves the performance of the persistent queue. Thanks! :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'LibraryListModel.qml'
2--- LibraryListModel.qml 2014-10-21 21:58:07 +0000
3+++ LibraryListModel.qml 2014-10-28 00:58:01 +0000
4@@ -24,79 +24,28 @@
5
6 Item {
7 id: libraryListModelItem
8+ property alias count: libraryModel.count
9 property ListModel model : ListModel {
10 id: libraryModel
11 property var linkLibraryListModel: libraryListModelItem
12 }
13- property alias count: libraryModel.count
14- property alias workerComplete: worker.completed
15+ property var param: null
16 property var query: null
17- property var param: null
18- property bool canLoad: true
19- property bool preLoadComplete: false
20-
21- onCanLoadChanged: {
22- /* If canLoad has been set back to true then check if there are any
23- remaining items to load in the model */
24- if (canLoad && worker.list !== null && !worker.completed)
25- {
26- worker.process();
27- }
28- }
29-
30 /* Pretent to be like a mediascanner2 listmodel */
31 property alias rowCount: libraryModel.count
32
33+ property alias canLoad: worker.canLoad
34+ property alias preLoadComplete: worker.preLoadComplete
35+ property alias syncFactor: worker.syncFactor
36+ property alias workerComplete: worker.completed
37+
38 function get(index, role) {
39 return model.get(index);
40 }
41
42- WorkerScript {
43- id: worker
44- source: "worker-library-loader.js"
45-
46- property bool completed: false
47- property int i: 0
48- property var list: null
49-
50- onListChanged: {
51- reset();
52- clear();
53- }
54-
55- onMessage: {
56- if (i === 0)
57- {
58- preLoadComplete = true;
59- }
60-
61- if (canLoad) // pause if the model is not allowed to load
62- {
63- process();
64- }
65- }
66-
67- function reset()
68- {
69- i = 0;
70- completed = false;
71- }
72-
73- // Add the next item in the list to the model otherwise set complete
74- function process()
75- {
76- if (worker.i < worker.list.length)
77- {
78- console.log(JSON.stringify(worker.list[worker.i]));
79- worker.sendMessage({'add': worker.list[worker.i],
80- 'model': libraryModel});
81- worker.i++;
82- }
83- else
84- {
85- worker.completed = true;
86- }
87- }
88+ WorkerModelLoader {
89+ id: worker
90+ model: libraryListModelItem.model
91 }
92
93 function indexOf(file)
94@@ -148,11 +97,4 @@
95
96 worker.list = Library.getRecent();
97 }
98-
99- function clear() {
100- if (worker.list !== null)
101- {
102- worker.sendMessage({'clear': true, 'model': libraryModel})
103- }
104- }
105 }
106
107=== modified file 'Player.qml'
108--- Player.qml 2014-10-28 00:58:01 +0000
109+++ Player.qml 2014-10-28 00:58:01 +0000
110@@ -123,7 +123,7 @@
111 }
112 else {
113 currentIndex = newIndex
114- source = Qt.resolvedUrl(trackQueue.model.get(newIndex).filename)
115+ setSource(Qt.resolvedUrl(trackQueue.model.get(newIndex).filename))
116 }
117
118 // Set index into queue
119
120=== added file 'WorkerModelLoader.qml'
121--- WorkerModelLoader.qml 1970-01-01 00:00:00 +0000
122+++ WorkerModelLoader.qml 2014-10-28 00:58:01 +0000
123@@ -0,0 +1,105 @@
124+/*
125+ * Copyright (C) 2014
126+ * Andrew Hayzen <ahayzen@gmail.com>
127+ * Victor Thompson <victor.thompson@gmail.com>
128+ *
129+ * This program is free software; you can redistribute it and/or modify
130+ * it under the terms of the GNU General Public License as published by
131+ * the Free Software Foundation; version 3.
132+ *
133+ * This program is distributed in the hope that it will be useful,
134+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
135+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
136+ * GNU General Public License for more details.
137+ *
138+ * You should have received a copy of the GNU General Public License
139+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
140+ */
141+
142+import QtQuick 2.3
143+
144+
145+WorkerScript {
146+ id: worker
147+ source: "worker-library-loader.js"
148+
149+ property bool canLoad: true
150+ property bool completed: false
151+ property int i: 0
152+ property var list: null
153+ property var model
154+ property bool preLoadComplete: false
155+ property int syncFactor: 5
156+
157+ onCanLoadChanged: {
158+ /* If canLoad has been set back to true then check if there are any
159+ remaining items to load in the model */
160+ if (canLoad && list !== null && !completed) {
161+ process();
162+ }
163+
164+ if (!canLoad) { // sync any pending changes when canLoad changes
165+ sync()
166+ }
167+ }
168+
169+ onListChanged: {
170+ reset();
171+ clear();
172+ }
173+
174+ onMessage: {
175+ if (messageObject.sync === true) {
176+ if (i >= list.length) { // if synced check if list now complete
177+ completed = true
178+ } else {
179+ return; // do not continue from a sync 'pong' only from a process/clear
180+ }
181+ }
182+
183+ if (i === 0) {
184+ preLoadComplete = true;
185+ }
186+
187+ if (canLoad && i % syncFactor === 0 && i !== 0) {
188+ sync();
189+ }
190+
191+ if (canLoad) { // pause if the model is not allowed to load
192+ process();
193+ }
194+
195+ if (i === 1) { // sync after the first item to prevent empty states
196+ sync()
197+ }
198+ }
199+
200+ function clear() {
201+ if (canLoad && list !== null) {
202+ sendMessage({'clear': true, 'model': model})
203+ }
204+ }
205+
206+ // Add the next item in the list to the model otherwise set complete
207+ function process()
208+ {
209+ if (i < list.length) {
210+ console.log(JSON.stringify(list[i]));
211+ sendMessage({'add': list[i], 'model': model});
212+ i++;
213+ } else {
214+ sync()
215+ }
216+ }
217+
218+ function reset()
219+ {
220+ i = 0;
221+ completed = false;
222+ }
223+
224+ function sync()
225+ {
226+ sendMessage({'sync': true, 'model': model});
227+ }
228+}
229
230=== modified file 'meta-database.js'
231--- meta-database.js 2014-10-28 00:58:01 +0000
232+++ meta-database.js 2014-10-28 00:58:01 +0000
233@@ -148,8 +148,7 @@
234 db.transaction( function(tx) {
235 var rs = tx.executeSql("SELECT * FROM queue ORDER BY ind ASC");
236 for(var i = 0; i < rs.rows.length; i++) {
237- var dbItem = rs.rows.item(i);
238- res.push({filename:dbItem.filename});
239+ res.push(makeDict(musicStore.lookup(rs.rows.item(i).filename)));
240 }
241 });
242 return res;
243
244=== modified file 'music-app.qml'
245--- music-app.qml 2014-10-28 00:58:01 +0000
246+++ music-app.qml 2014-10-28 00:58:01 +0000
247@@ -235,6 +235,9 @@
248 }
249
250 function process(uri, play) {
251+ // stop loading the queue as we will load from uriHandler
252+ queueLoaderWorker.canLoad = false
253+
254 if (uri.indexOf("album:///") === 0) {
255 uriHandler.processAlbum(uri.substring(9));
256 }
257@@ -244,7 +247,6 @@
258 else if (uri.indexOf("music://") === 0) {
259 uriHandler.processFile(uri.substring(8), play);
260 }
261-
262 else {
263 console.debug("Unsupported URI " + uri + ", skipping")
264 }
265@@ -533,6 +535,21 @@
266 width: units.gu(100)
267 height: units.gu(80)
268
269+ WorkerModelLoader {
270+ id: queueLoaderWorker
271+ canLoad: false
272+ list: Library.getQueue()
273+ model: trackQueue.model
274+ syncFactor: 10
275+
276+ onCompletedChanged: {
277+ if (completed) {
278+ player.currentIndex = queueIndex
279+ player.setSource(list[queueIndex].filename)
280+ }
281+ }
282+ }
283+
284 // Run on startup
285 Component.onCompleted: {
286 customdebug("Version "+appVersion) // print the curren version
287@@ -542,28 +559,12 @@
288
289 Library.initialize();
290
291- // Load previous queue
292- if (!Library.isQueueEmpty()) {
293- var queue = Library.getQueue()
294- for (var i = 0; i < queue.length; i++) {
295- trackQueue.model.append({
296- album:musicStore.lookup(queue[i].filename).album,
297- art:musicStore.lookup(queue[i].filename).art,
298- author:musicStore.lookup(queue[i].filename).author,
299- filename:queue[i].filename,
300- title:musicStore.lookup(queue[i].filename).title
301- })
302- }
303-
304- if (queue.length > queueIndex) {
305- player.currentIndex = queueIndex
306- player.setSource(queue[queueIndex].filename)
307- }
308- }
309-
310 // initialize playlists
311 Playlists.initializePlaylist()
312
313+ // allow the queue loader to start
314+ queueLoaderWorker.canLoad = !Library.isQueueEmpty()
315+
316 // everything else
317 loading.visible = true
318
319
320=== modified file 'worker-library-loader.js'
321--- worker-library-loader.js 2014-05-23 15:00:21 +0000
322+++ worker-library-loader.js 2014-10-28 00:58:01 +0000
323@@ -19,15 +19,14 @@
324
325
326 WorkerScript.onMessage = function(msg) {
327- if (msg.clear === true)
328- {
329+ if (msg.clear === true) {
330 msg.model.clear();
331- }
332- else
333- {
334+ WorkerScript.sendMessage({});
335+ } else if (msg.sync === true) {
336+ msg.model.sync(); // updates the changes to the list
337+ WorkerScript.sendMessage({"sync": true});
338+ } else {
339 msg.model.append(msg.add);
340+ WorkerScript.sendMessage({});
341 }
342- msg.model.sync(); // updates the changes to the list
343-
344- WorkerScript.sendMessage({});
345 }

Subscribers

People subscribed via source and target branches