Skip to content

Commit

Permalink
cache the current version of fhc as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei Li committed Jun 19, 2015
1 parent b485dc0 commit db34c89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Release 1.1.4 - 2015-06-19 - Wei Li
------------------------------------------------------
* Cache the current version of fhc so that the cached data will be invalidated if fhc version is changed.

Release 1.1.3 - 2015-06-16 - Wei Li
------------------------------------------------------
* Fix the version check. Use npm.js instead.
Expand Down
21 changes: 16 additions & 5 deletions lib/cmd/common/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ var fhc = require('../../fhc'),
const dayInMs = 86400000;
const daysToCache = 1;
const timeout = 2000;
const PATTERN = /-BUILD-NUMBER/;

function cleanupVersion(version){
if(PATTERN.test(version)){
return version.replace(PATTERN, '');
}
return version;
}

module.exports = {
'desc': 'Version info about the FeedHenry instance we\'re connected to',
Expand Down Expand Up @@ -41,9 +49,11 @@ module.exports = {
cachedLatest = JSON.parse(cachedLatest)
} catch (error) {}
if (!_.isEmpty(cachedLatest)) {
if (cachedLatest.ts - (new Date().getTime() - (dayInMs * daysToCache)) > 0) {
self.latest = cachedLatest;
return cb(cachedLatest.is);
if(cachedLatest.current && semver.eq(cleanupVersion(cachedLatest.current), cleanupVersion(fhc._version))){
if (cachedLatest.ts - (new Date().getTime() - (dayInMs * daysToCache)) > 0) {
self.latest = cachedLatest;
return cb(cachedLatest.is);
}
}
}

Expand All @@ -63,12 +73,13 @@ module.exports = {
}
var latestV = body.version,
localV = fhc._version,
isUpToDate = semver.gte(localV, latestV);
isUpToDate = semver.gte(cleanupVersion(localV), cleanupVersion(latestV));

self.latest = {
version: latestV,
is: isUpToDate,
ts: new Date().getTime()
ts: new Date().getTime(),
current: fhc._version
};

// Cache the result
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fh-fhc",
"description": "A Command Line Interface for FeedHenry",
"version": "1.1.3-BUILD-NUMBER",
"version": "1.1.4-BUILD-NUMBER",
"keywords": [
"feedhenry"
],
Expand Down Expand Up @@ -30,7 +30,7 @@
"nopt": "1.0.0",
"open": "0.0.5",
"request": "2.11.4",
"semver": "1.0.14",
"semver": "4.3.6",
"tabtab": "0.0.2",
"underscore": "1.5.2",
"underscore-deep-extend": "0.0.5",
Expand Down

0 comments on commit db34c89

Please sign in to comment.