Merge lp:~etherpulse/podbird/duplicated_downloads into lp:podbird/devel

Proposed by Eran Uzan
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 158
Merged at revision: 156
Proposed branch: lp:~etherpulse/podbird/duplicated_downloads
Merge into: lp:podbird/devel
Diff against target: 97 lines (+37/-12)
3 files modified
app/podbird.qml (+31/-7)
app/podcasts.js (+5/-4)
po/podbird.nik90.pot (+1/-1)
To merge this branch: bzr merge lp:~etherpulse/podbird/duplicated_downloads
Reviewer Review Type Date Requested Status
Nekhelesh Ramananthan Needs Fixing
Review via email: mp+309618@code.launchpad.net

Description of the change

Fix for download duplication when restarting Podbird.

Bug: lp:1637657

To post a comment you must log in.
Revision history for this message
Eran Uzan (etherpulse) wrote :

This will create a conflict with my other MP to implement lp:1456300 ...
But i`ll be happy to fix it if needed :)

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Time to review this. So I get most of the logic here. Before Podbird downloads an episode, it checks if the guid is already present in DownloadManager's list. What I don't get is why that delay timer is required. Can you explain that? Is it because DownloadManager takes a few ms to load and so this check needs to be delayed until that happens?

review: Needs Information
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Here in,

+ var item = rs2.rows.item(j);
+ if (!item.downloadedfile && !item.listened && item.audiourl && !item.queued ) {
+ podbird.downloadEpisode(item.image, item.name, item.guid, item.audiourl )
+ tx.executeSql("UPDATE Episode SET queued=1 WHERE guid = ?", [item.guid]);

Here I think item can be better renamed as episode don't you think?

Revision history for this message
Eran Uzan (etherpulse) wrote :

Hey :)

Exactly, I know the timer is ugly but for some reason all the onCompleted events happen before the downloads list is populated so the downloads list is empty when we add episodes and theres nothing to compare against.
I couldn't find any way around it (checked a lots of onCompleted and other single shot events :/ )
I think I can decrease the timer delay to even 1 millisecond and it will still work my guess it`s some kind of single UI thread issue.

And yeah episode will make more sense i`ll change it.. thanks :)

156. By Eran Uzan

Changed variable name to make the code clearer

Revision history for this message
Eran Uzan (etherpulse) wrote :

Hey ,
I identified an issue with the version on this branch it seems that the episode the are marked for download don['t have the podcast image assigned to them.

I`l investigate and come back to you in any case i suggest not to merge this branch for now...

Revision history for this message
Eran Uzan (etherpulse) wrote :

OK I've "investigated" and found out.. that I`m stupid... I used episode.image instead of podcast.image :)

157. By Eran Uzan

Fix regression that caused a missing podcast image on the download tab

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Please bear with me while I try to brainstorming an idea here, I keep wondering why we have the following code outside of the DownloadManager,

8 - if (!NetworkingStatus.online || settings.maxEpisodeDownload === -1) {
9 - console.log("[LOG]: Skipped autodownloading of new episodes...")
10 - console.log("[LOG]: Online connectivity: " + NetworkingStatus.online)
11 - console.log("[LOG]: User settings (maxEpisodeDownload): " + settings.maxEpisodeDownload)
12 - } else {
13 - Podcasts.autoDownloadEpisodes(settings.maxEpisodeDownload)

Why can't we move this code insider the DownloadManger onCompleted{} scope? I mean, you anyway can't autodownload episodes before the DownloadManager as finished loading. So couldn't we wait for DownloadManager and then it runs the autodownloader code? This might even help the Timer.

Can you give that a try?

review: Needs Information
Revision history for this message
Eran Uzan (etherpulse) wrote :

Giving it at try! :)

Revision history for this message
Eran Uzan (etherpulse) wrote :

Hmm it seem that the DownloadManager.onCompleted signal happen even earlier then the MainView onCompleted signal it seems that any part of the MainView recevied the onCompleted signal before the main view so it doesn't really works.

I did find that if I attach it to the onStateChanged of the Qt.application it will work however this as the side effect of checking for new downloads every time podbird is brught to the front instead of a single time at the application lunch.

I`ll keep searching for other events maybe i should dynamically load the DownloadManager or some other method...

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Hi Eran, I am going to go ahead and merge this. We can come up with a better method later. Thanks for the patch and noticing the bug in the first place.

review: Approve
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Hmm on second thought, I am getting code conflicts with devel branch. Can you merge lp:podbird/devel, fix the conflicts and update it. I will then merge it asap.

review: Needs Fixing
Revision history for this message
Eran Uzan (etherpulse) wrote :

Will do once i get home.

158. By Eran Uzan

Merged with lp:podbird/devel

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/podbird.qml'
2--- app/podbird.qml 2016-11-16 21:49:13 +0000
3+++ app/podbird.qml 2016-11-28 09:51:07 +0000
4@@ -78,12 +78,21 @@
5 settings.lastCheck = today
6 }
7
8- if (!NetworkingStatus.online || settings.maxEpisodeDownload === -1) {
9- console.log("[LOG]: Skipped autodownloading of new episodes...")
10- console.log("[LOG]: Online connectivity: " + NetworkingStatus.online)
11- console.log("[LOG]: User settings (maxEpisodeDownload): " + settings.maxEpisodeDownload)
12- } else {
13- Podcasts.autoDownloadEpisodes(settings.maxEpisodeDownload)
14+ delayStartTimer.start();
15+ }
16+
17+ Timer {
18+ id: delayStartTimer
19+ interval: 500
20+ repeat: false
21+ onTriggered: {
22+ if (!NetworkingStatus.online || podbird.settings.maxEpisodeDownload === -1) {
23+ console.log("[LOG]: Skipped autodownloading of new episodes...")
24+ console.log("[LOG]: Online connectivity: " + NetworkingStatus.online)
25+ console.log("[LOG]: User settings (maxEpisodeDownload): " + podbird.settings.maxEpisodeDownload)
26+ } else {
27+ Podcasts.autoDownloadEpisodes(podbird.settings.maxEpisodeDownload)
28+ }
29 }
30 }
31
32@@ -173,7 +182,12 @@
33 }
34
35 function downloadEpisode(image, title, guid, url, disableMobileDownload) {
36- var singleDownload = singleDownloadComponent.createObject(podbird, {"image": image, "title": title, "guid": guid , allowMobileDownload : !disableMobileDownload })
37+ if(downloader.isDownloadInQueue(guid)) {
38+ console.log("[LOG]: Download with GUID of :"+guid+ " is already in the download queue.")
39+ return false;
40+ }
41+
42+ var singleDownload = singleDownloadComponent.createObject(podbird, {"image": image, "title": title, "guid": guid, allowMobileDownload : !disableMobileDownload })
43 singleDownload.download(url)
44 }
45
46@@ -184,6 +198,16 @@
47 property int progress: downloads.length > 0 ? downloads[0].progress : 0
48
49 cleanDownloads: true
50+
51+ function isDownloadInQueue ( guid ) {
52+ for( var i=0; i < downloads.length; i++) {
53+ if( downloads[i].metadata.custom.guid && guid === downloads[i].metadata.custom.guid) {
54+ return true ;
55+ }
56+ }
57+ return false;
58+ }
59+
60 onDownloadFinished: {
61 var db = Podcasts.init();
62 var finalLocation = fileManager.saveDownload(path);
63
64=== modified file 'app/podcasts.js'
65--- app/podcasts.js 2016-10-24 19:08:35 +0000
66+++ app/podcasts.js 2016-11-28 09:51:07 +0000
67@@ -356,12 +356,13 @@
68 var rs = tx.executeSql("SELECT rowid, * FROM Podcast ORDER BY name ASC");
69 for (var i=0; i < rs.rows.length; i++) {
70 var podcast = rs.rows.item(i);
71- var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=? ORDER BY published DESC", [rs.rows.item(i).rowid]);
72+ var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=? ORDER BY published DESC", [podcast.rowid]);
73 var loopCount = maxEpisodeDownload > rs2.rows.length ? rs2.rows.length : maxEpisodeDownload
74 for (var j=0; j < loopCount; j++) {
75- if (!rs2.rows.item(j).downloadedfile && !rs2.rows.item(j).listened && rs2.rows.item(j).audiourl) {
76- podbird.downloadEpisode(rs.rows.item(i).image, rs2.rows.item(j).name, rs2.rows.item(j).guid, rs2.rows.item(j).audiourl, podbird.settings.downloadOverWifiOnly)
77- tx.executeSql("UPDATE Episode SET queued=1 WHERE guid = ?", [rs2.rows.item(j).guid]);
78+ var episode = rs2.rows.item(j);
79+ if ( !episode.downloadedfile && !episode.listened && episode.audiourl && !episode.queued ) {
80+ podbird.downloadEpisode(podcast.image, episode.name, episode.guid, episode.audiourl, podbird.settings.downloadOverWifiOnly)
81+ tx.executeSql("UPDATE Episode SET queued=1 WHERE guid = ?", [episode.guid]);
82 }
83 }
84 }
85
86=== modified file 'po/podbird.nik90.pot'
87--- po/podbird.nik90.pot 2016-10-24 19:08:35 +0000
88+++ po/podbird.nik90.pot 2016-11-28 09:51:07 +0000
89@@ -8,7 +8,7 @@
90 msgstr ""
91 "Project-Id-Version: \n"
92 "Report-Msgid-Bugs-To: \n"
93-"POT-Creation-Date: 2016-10-24 19:03+0000\n"
94+"POT-Creation-Date: 2016-11-28 09:45+0000\n"
95 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
96 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
97 "Language-Team: LANGUAGE <LL@li.org>\n"

Subscribers

People subscribed via source and target branches

to all changes: