Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support maxage for uplinks #47

Merged
merged 1 commit into from
Mar 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Storage.prototype.update_versions = function(name, newdata, callback) {
}
for (var up in newdata._uplinks) {
var need_change =
!utils.is_object(data._uplinks[up]) || (newdata._uplinks[up].etag !== data._uplinks[up].etag)
!utils.is_object(data._uplinks[up]) || (newdata._uplinks[up].etag !== data._uplinks[up].etag || (newdata._uplinks[up].fetched !== data._uplinks[up].fetched))

if (need_change) {
change = true
Expand Down
14 changes: 12 additions & 2 deletions lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,19 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options,

async.map(uplinks, function(up, cb) {
var _options = Object.create(options)
if (utils.is_object(pkginfo._uplinks[up.upname]))
if (utils.is_object(pkginfo._uplinks[up.upname])) {
var fetched = pkginfo._uplinks[up.upname].fetched
if (fetched && fetched > (Date.now() - up.maxage)) {
return cb()
}

_options.etag = pkginfo._uplinks[up.upname].etag
}

up.get_package(name, _options, function(err, up_res, etag) {
if (err && err.message === "bad status code: 304")
pkginfo._uplinks[up.upname].fetched = Date.now()

if (err || !up_res) return cb(null, [err || new Error('no data')])

try {
Expand All @@ -356,7 +365,8 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options,
}

pkginfo._uplinks[up.upname] = {
etag: etag
etag: etag,
fetched: Date.now()
}

try {
Expand Down
1 change: 1 addition & 0 deletions lib/up-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function Storage(config, mainconfig) {
this.logger = Logger.logger.child({sub: 'out'})
this.server_id = mainconfig.server_id

this.maxage = (parseInt(this.config.maxage, 10) || 0) * 1000
this.url = URL.parse(this.config.url)
if (this.url.hostname === 'registry.npmjs.org') {
// npm registry is too slow working with ssl :(
Expand Down