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
1=== modified file 'components/WeatherApi.js'
2--- components/WeatherApi.js 2014-03-03 13:26:03 +0000
3+++ components/WeatherApi.js 2014-03-06 20:42:53 +0000
4@@ -728,14 +728,14 @@
5 api_key: message.params.api_key
6 },
7 secsFromLastFetch = (now-loc.updated)/1000;
8- //
9- if( message.params.force===true || loc.format !== RESPONSE_DATA_VERSION || secsFromLastFetch > 1800){
10+ // cache check deactivated, due to https://bugs.launchpad.net/ubuntu-weather-app/+bug/1287446
11+ /*if( message.params.force===true || loc.format !== RESPONSE_DATA_VERSION || secsFromLastFetch > 1800){*/
12 // data older than 30min, location is new or data format is deprecated
13 WeatherApi.getLocationData(params, updatedHnd, onError);
14- } else {
15+ /*} else {
16 console.log("["+loc.location.name+"] returning cached data, time from last fetch: "+secsFromLastFetch)
17 updatedHnd(loc, true);
18- }
19+ }*/
20 })
21 } else {
22 finished(result);
23
24=== modified file 'ubuntu-weather-app.qml'
25--- ubuntu-weather-app.qml 2014-02-26 17:08:11 +0000
26+++ ubuntu-weather-app.qml 2014-03-06 20:42:53 +0000
27@@ -104,15 +104,26 @@
28 WorkerScript {
29 id: locationDataWorker
30 source: "components/WeatherApi.js"
31+ property int response_data_version: 20131207
32+ // temporary cache for data while WorkerScript runs
33+ property var tempData: ({})
34 onMessage: {
35+ var refreshedLocations = [];
36 if(!messageObject.error) {
37 if(messageObject.action === "updateData") {
38 messageObject.result.forEach(function(loc) {
39+ // replace location data in cache with refreshed values
40+ tempData[loc.db.id] = loc;
41 if(loc["save"] === true) {
42 storage.updateLocation(loc.db.id, loc);
43 }
44 });
45- buildTabs(messageObject.result);
46+ // now build a new list of locations
47+ for(var db_id in tempData) {
48+ refreshedLocations.push(tempData[db_id]);
49+ }
50+ tempData = ({}) // clear cache
51+ buildTabs(refreshedLocations);
52 }
53 } else {
54 console.log(messageObject.error.msg+" / "+messageObject.error.request.url)
55@@ -120,6 +131,34 @@
56 refreshData(true, null);
57 }
58 }
59+
60+ function loadLocations(locations, force_refresh) {
61+ var locsToLoad = [],
62+ now = new Date().getTime();
63+ locations.forEach(function(location) {
64+ var secsFromLastFetch = (now-location.updated)/1000;
65+ // add data for the cache
66+ tempData[location.db.id] = location;
67+ if( force_refresh===true || location.format !== response_data_version || secsFromLastFetch > 1800) {
68+ // location shoudl get refreshed
69+ locsToLoad.push(location);
70+ }
71+ });
72+ if(locsToLoad.length > 0) {
73+ sendMessage({
74+ action: "updateData",
75+ params: {
76+ locations:locsToLoad,
77+ force:force_refresh,
78+ service:settings["service"],
79+ api_key: Key.twcKey
80+ }
81+ })
82+ } else {
83+ tempData = ({}) // clear cache again, not needed
84+ buildTabs(locations);
85+ }
86+ }
87 }
88
89 ParallelAnimation {
90@@ -199,16 +238,8 @@
91 if(from_storage === true && force_refresh !== true) {
92 storage.getLocations(buildTabs);
93 } else {
94- storage.getLocations(function(locations) {
95- locationDataWorker.sendMessage({
96- action: "updateData",
97- params: {
98- locations:locations,
99- force:force_refresh,
100- service:settings["service"],
101- api_key: Key.twcKey
102- }
103- })
104+ storage.getLocations(function(locations) {
105+ locationDataWorker.loadLocations(locations, force_refresh)
106 });
107 }
108 }

Subscribers

People subscribed via source and target branches