From 8d7d79e7c8e61c8811f321e28d12f0615eadeedd Mon Sep 17 00:00:00 2001 From: Jason Abbott Date: Wed, 12 Apr 2017 22:53:00 -0600 Subject: [PATCH] fix map caching in redis --- CHANGELOG.md | 3 +++ lib/cache.js | 2 +- lib/controller.js | 3 +++ lib/factory.js | 23 ++++++++++++----------- lib/library.js | 31 ++++++++++++++++--------------- lib/redis.js | 17 ++++++++++++----- 6 files changed, 47 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 053367b1..1b6a4ff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.2.4 +- Fix bad GPX caching in Redis + ## 2.2.3 - Update dependencies - Use memory instead of Redis to cache views diff --git a/lib/cache.js b/lib/cache.js index b3080213..345c9fbb 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -251,7 +251,7 @@ module.exports = { * @returns {Promise.} */ add: (key, geoJSON) => addItem(mapKey, key, geoJSON, config.cache.maps), - + /** * Whether cache map exists * @param {string} key diff --git a/lib/controller.js b/lib/controller.js index 6491d461..436bd635 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -9,6 +9,9 @@ const template = require('./template'); const factory = require('./factory'); const library = require('./library'); const C = require('./constants'); +/** + * Route placeholders + */ const ph = C.route; /** diff --git a/lib/factory.js b/lib/factory.js index 328bb8a7..1249d247 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -560,9 +560,9 @@ function buildSearchPhoto(json, sizeField) { } /** - * @param {Object} json - * @param {String|String[]} sizeField Size or list of size field names in order of preference - * @returns {Size|Object} + * @param {object} json + * @param {string|string[]} sizeField Size or list of size field names in order of preference + * @returns {Size|object} */ function buildPhotoSize(json, sizeField) { const size = { @@ -649,7 +649,6 @@ function identifyPhotoDateOutliers(photos) { /** * Coordinate property used by Google's static maps - * @returns {String} Comma delimited list of coordinates * @this {Post} * @see https://developers.google.com/maps/documentation/static-maps/intro */ @@ -675,14 +674,14 @@ function serializePhotoCoordinates() { //= EXIF ====================================================================== /** - * @param {String} photoID + * @param {string} photoID * @returns {Promise} */ function getEXIF(photoID) { return flickr.getExif(photoID).then(buildExif); } /** * @param {Flickr.PhotoExif} flickrExif - * @return {EXIF|Object} + * @return {EXIF|object} */ function buildExif(flickrExif) { const parser = (exif, tag, empty = null) => { @@ -704,7 +703,7 @@ function buildExif(flickrExif) { } /** - * @param {EXIF|Object} exif + * @param {EXIF|object} exif * @returns {EXIF} */ function sanitizeExif(exif) { @@ -767,7 +766,7 @@ const cache = require('./cache'); /** * Load all map information (track and photo features) for a post - * @param {String} postKey + * @param {string} postKey * @returns {Promise.} * @see http://geojsonlint.com/ */ @@ -776,7 +775,9 @@ const mapForPost = postKey => config.cache.maps : loadMapForPost(postKey); /** - * @param {String} postKey + * Get GeoJSON for map. If post has no track then GPX will only include photo + * markers. + * @param {string} postKey * @returns {Promise.} */ function loadMapForPost(postKey) { @@ -789,7 +790,7 @@ function loadMapForPost(postKey) { ? noGPX : google.drive.loadGPX(post) .then(map.featuresFromGPX) - .catch(err => noGPX); + .catch(() => noGPX); return getFeatures .then(geo => mapPhotoFeatures(post, geo)) @@ -800,7 +801,7 @@ function loadMapForPost(postKey) { * Append photo GeoFeatures to GeoJSON * @param {Post} post * @param {GeoJSON.FeatureCollection} [geo] - * @returns {Promise.} GeoJSON + * @returns {Promise.} GeoJSON */ const mapPhotoFeatures = (post, geo) => new Promise(resolve => { // move to the first post in a series diff --git a/lib/library.js b/lib/library.js index 2d53a231..c83c4b1e 100644 --- a/lib/library.js +++ b/lib/library.js @@ -1,15 +1,16 @@ const is = require('./is'); /** - * Singleton collection of photos grouped into "posts" (called a "set" or "album" in most providers) - * that are in turn assigned categories. Additional library methods are added by the factory. + * Singleton collection of photos grouped into "posts" (called a "set" or + * "album" in most providers) that are in turn assigned categories. Additional + * library methods are added by the factory. * @see addHelperMethods * @type {Library} */ module.exports = { /** * Root categories indexed by their name - * @type {Object.} + * @type {object.} */ categories: {}, /** @@ -19,7 +20,7 @@ module.exports = { posts: [], /** * All photo tags in hash[slug] = full name format - * @type {Object.} + * @type {object.} */ tags: {}, loaded: false, @@ -27,7 +28,7 @@ module.exports = { /** * Track keys of posts and categories that change on library reload * (can be used for cache invalidation) - * @type {String[]} + * @type {string[]} */ changedKeys: [], @@ -42,14 +43,14 @@ module.exports = { /** * Array of all post keys - * @returns {String[]} + * @returns {string[]} */ postKeys() { return this.posts.map(p => p.key); }, /** * Array of all category keys - * @param {String[]} [filterList] List of category names or all if no list given - * @returns {String[]} + * @param {string[]} [filterList] List of category names or all if no list given + * @returns {string[]} */ categoryKeys(filterList = []) { const keys = []; @@ -82,7 +83,7 @@ module.exports = { /** * Find category with given key - * @param {String} key + * @param {string} key * @returns {Category} */ categoryWithKey(key) { @@ -99,15 +100,15 @@ module.exports = { /** * Find post with given ID - * @param {String} id + * @param {string} id * @returns {Post} */ postWithID(id) { return this.posts.find(p => p.id == id); }, /** * Find post with given slug - * @param {String} key - * @param {String} [partKey] + * @param {string} key + * @param {string} [partKey] * @returns {Post} */ postWithKey(key, partKey) { @@ -117,7 +118,7 @@ module.exports = { /** * Unload particular posts to force refresh from source - * @param {String|String[]} keys + * @param {string|string[]} keys */ unload(keys) { if (!is.array(keys)) { keys = [keys]; } @@ -130,7 +131,7 @@ module.exports = { /** * Remove posts (primarily for testing) - * @param {String|String[]} keys + * @param {string|string[]} keys */ remove(keys) { if (!is.array(keys)) { keys = [keys]; } @@ -146,7 +147,7 @@ module.exports = { /** * Get unique list of tags used on photos in the post and update photo tags to use full names * @param {Photo[]} photos - * @returns {String} Unique list of photo tags + * @returns {string} Unique list of photo tags */ photoTagList(photos) { // all photo tags in the post diff --git a/lib/redis.js b/lib/redis.js index a33e63aa..aa3edf22 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -79,7 +79,7 @@ client.on('end', ()=> { function normalize(value) { if (typeof value == is.type.OBJECT) { const cache = require('./cache'); - return is.cacheItem(value) ? cache.view.serialize(value) : JSON.stringify(value); + return is.cacheItem(value) ? cache.redisView.serialize(value) : JSON.stringify(value); } else { return value; } @@ -91,16 +91,23 @@ function normalize(value) { * @returns {object} */ function parseObject(value) { - return is.empty(value) ? null : JSON.parse(value); + if (is.empty(value)) { return null; } + + try { + return JSON.parse(value) + } catch (err) { + log.error('Unable to JSON parse "%s"', value); + return null; + } } /** * Normalize response * @param {string} key Cache key * @param {number} type Data type - * @param {Function} resolve - * @param {Function} reject - * @returns {Function} + * @param {function} resolve + * @param {function} reject + * @returns {function} */ function makeHandler(key, type = dataType.NONE, resolve, reject) { // calculate expected response