From ff038a70c48f76180bcfca12eaf7e4001355605d Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Thu, 18 Oct 2018 21:41:42 +0100 Subject: [PATCH] Some caching fixes --- src/service-worker.js | 2 +- src/v1/js/Location.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/service-worker.js b/src/service-worker.js index 39cddce..9845256 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -const CACHE_VERSION = { 'version': '0.0.891' }; +const CACHE_VERSION = { 'version': '0.0.892' }; const PRECACHE = `jubileeData-${CACHE_VERSION.version}`; const RUNTIME = 'runtime'; diff --git a/src/v1/js/Location.js b/src/v1/js/Location.js index a00e6bd..46f3a5a 100644 --- a/src/v1/js/Location.js +++ b/src/v1/js/Location.js @@ -57,9 +57,9 @@ const LocationModel = Backbone.Model.extend({ if (now.getTime() - this.throttler > 30000) { this.processPosition(location); this.throttler = now.getTime() + 1000; - } else { - console.log('Throttling location update...'); } + else + console.log('Throttling location update...'); // this.set('location', location); }.bind(this)); @@ -98,6 +98,14 @@ const LocationModel = Backbone.Model.extend({ // rawburn house 51.490002, -0.140245 // thomas more 51.5084707,-0.068798 + const distanceFromLast = distance(current.latitude, current.longitude, latitude, longitude); + + if (distanceFromLast < 0.001) { + console.log('Insignificant distance, bail'); + + return; + } + const geocoder = NodeGeocoder(options); // 55.872407, -3.549003 const homeDistance = distance(myCoords.home.lat, myCoords.home.long, latitude, longitude); @@ -141,7 +149,7 @@ const LocationModel = Backbone.Model.extend({ else { newLocation.city = current.city; const currentTime = new Date().getTime(); - const distanceFromLast = distance(current.latitude, current.longitude, latitude, longitude); + const lastGeocode = this.get('lastGeocode'); const distanceFromLastGeocode = distance(lastGeocode.lat, lastGeocode.lng, latitude, longitude);