Merge lp:~martin-borho/ubuntu-weather-app/bug-1287446 into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Martin Borho
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 215
Merged at revision: 216
Proposed branch: lp:~martin-borho/ubuntu-weather-app/bug-1287446
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 108 lines (+46/-15)
2 files modified
components/WeatherApi.js (+4/-4)
ubuntu-weather-app.qml (+42/-11)
To merge this branch: bzr merge lp:~martin-borho/ubuntu-weather-app/bug-1287446
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Nicholas Skaggs (community) Approve
Review via email: mp+209777@code.launchpad.net

Commit message

workaround for Bug #1287446, only starting WorkerScript for newly added / outdated locations, or when an update is forced.

Description of the change

workaround for Bug #1287446, only starting WorkerScript for newly added / outdated locations, or when an update is forced.

To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

I was unable to reproduce the specific issue mentioned in the bug after applying this branch. +1 from me.

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 'components/WeatherApi.js'
--- components/WeatherApi.js 2014-03-03 13:26:03 +0000
+++ components/WeatherApi.js 2014-03-06 20:42:53 +0000
@@ -728,14 +728,14 @@
728 api_key: message.params.api_key728 api_key: message.params.api_key
729 },729 },
730 secsFromLastFetch = (now-loc.updated)/1000;730 secsFromLastFetch = (now-loc.updated)/1000;
731 //731 // cache check deactivated, due to https://bugs.launchpad.net/ubuntu-weather-app/+bug/1287446
732 if( message.params.force===true || loc.format !== RESPONSE_DATA_VERSION || secsFromLastFetch > 1800){732 /*if( message.params.force===true || loc.format !== RESPONSE_DATA_VERSION || secsFromLastFetch > 1800){*/
733 // data older than 30min, location is new or data format is deprecated733 // data older than 30min, location is new or data format is deprecated
734 WeatherApi.getLocationData(params, updatedHnd, onError);734 WeatherApi.getLocationData(params, updatedHnd, onError);
735 } else {735 /*} else {
736 console.log("["+loc.location.name+"] returning cached data, time from last fetch: "+secsFromLastFetch)736 console.log("["+loc.location.name+"] returning cached data, time from last fetch: "+secsFromLastFetch)
737 updatedHnd(loc, true);737 updatedHnd(loc, true);
738 }738 }*/
739 })739 })
740 } else {740 } else {
741 finished(result);741 finished(result);
742742
=== modified file 'ubuntu-weather-app.qml'
--- ubuntu-weather-app.qml 2014-02-26 17:08:11 +0000
+++ ubuntu-weather-app.qml 2014-03-06 20:42:53 +0000
@@ -104,15 +104,26 @@
104 WorkerScript {104 WorkerScript {
105 id: locationDataWorker105 id: locationDataWorker
106 source: "components/WeatherApi.js"106 source: "components/WeatherApi.js"
107 property int response_data_version: 20131207
108 // temporary cache for data while WorkerScript runs
109 property var tempData: ({})
107 onMessage: {110 onMessage: {
111 var refreshedLocations = [];
108 if(!messageObject.error) {112 if(!messageObject.error) {
109 if(messageObject.action === "updateData") {113 if(messageObject.action === "updateData") {
110 messageObject.result.forEach(function(loc) {114 messageObject.result.forEach(function(loc) {
115 // replace location data in cache with refreshed values
116 tempData[loc.db.id] = loc;
111 if(loc["save"] === true) {117 if(loc["save"] === true) {
112 storage.updateLocation(loc.db.id, loc);118 storage.updateLocation(loc.db.id, loc);
113 }119 }
114 });120 });
115 buildTabs(messageObject.result);121 // now build a new list of locations
122 for(var db_id in tempData) {
123 refreshedLocations.push(tempData[db_id]);
124 }
125 tempData = ({}) // clear cache
126 buildTabs(refreshedLocations);
116 }127 }
117 } else {128 } else {
118 console.log(messageObject.error.msg+" / "+messageObject.error.request.url) 129 console.log(messageObject.error.msg+" / "+messageObject.error.request.url)
@@ -120,6 +131,34 @@
120 refreshData(true, null);131 refreshData(true, null);
121 }132 }
122 }133 }
134
135 function loadLocations(locations, force_refresh) {
136 var locsToLoad = [],
137 now = new Date().getTime();
138 locations.forEach(function(location) {
139 var secsFromLastFetch = (now-location.updated)/1000;
140 // add data for the cache
141 tempData[location.db.id] = location;
142 if( force_refresh===true || location.format !== response_data_version || secsFromLastFetch > 1800) {
143 // location shoudl get refreshed
144 locsToLoad.push(location);
145 }
146 });
147 if(locsToLoad.length > 0) {
148 sendMessage({
149 action: "updateData",
150 params: {
151 locations:locsToLoad,
152 force:force_refresh,
153 service:settings["service"],
154 api_key: Key.twcKey
155 }
156 })
157 } else {
158 tempData = ({}) // clear cache again, not needed
159 buildTabs(locations);
160 }
161 }
123 }162 }
124163
125 ParallelAnimation {164 ParallelAnimation {
@@ -199,16 +238,8 @@
199 if(from_storage === true && force_refresh !== true) {238 if(from_storage === true && force_refresh !== true) {
200 storage.getLocations(buildTabs);239 storage.getLocations(buildTabs);
201 } else { 240 } else {
202 storage.getLocations(function(locations) { 241 storage.getLocations(function(locations) {
203 locationDataWorker.sendMessage({242 locationDataWorker.loadLocations(locations, force_refresh)
204 action: "updateData",
205 params: {
206 locations:locations,
207 force:force_refresh,
208 service:settings["service"],
209 api_key: Key.twcKey
210 }
211 })
212 });243 });
213 }244 }
214 }245 }

Subscribers

People subscribed via source and target branches