mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
Merge pull request #47 from samcday/maxage-support
Support maxage for uplinks
This commit is contained in:
commit
3b510437a8
@ -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
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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 :(
|
||||
|
Loading…
Reference in New Issue
Block a user