mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-03 23:09:17 -05:00
Merge pull request #47 from samcday/maxage-support
Support maxage for uplinks
This commit is contained in:
commit
3b510437a8
3 changed files with 14 additions and 3 deletions
|
@ -167,7 +167,7 @@ Storage.prototype.update_versions = function(name, newdata, callback) {
|
||||||
}
|
}
|
||||||
for (var up in newdata._uplinks) {
|
for (var up in newdata._uplinks) {
|
||||||
var need_change =
|
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) {
|
if (need_change) {
|
||||||
change = true
|
change = true
|
||||||
|
|
|
@ -339,10 +339,19 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options,
|
||||||
|
|
||||||
async.map(uplinks, function(up, cb) {
|
async.map(uplinks, function(up, cb) {
|
||||||
var _options = Object.create(options)
|
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
|
_options.etag = pkginfo._uplinks[up.upname].etag
|
||||||
|
}
|
||||||
|
|
||||||
up.get_package(name, _options, function(err, up_res, 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')])
|
if (err || !up_res) return cb(null, [err || new Error('no data')])
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -356,7 +365,8 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options,
|
||||||
}
|
}
|
||||||
|
|
||||||
pkginfo._uplinks[up.upname] = {
|
pkginfo._uplinks[up.upname] = {
|
||||||
etag: etag
|
etag: etag,
|
||||||
|
fetched: Date.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -20,6 +20,7 @@ function Storage(config, mainconfig) {
|
||||||
this.logger = Logger.logger.child({sub: 'out'})
|
this.logger = Logger.logger.child({sub: 'out'})
|
||||||
this.server_id = mainconfig.server_id
|
this.server_id = mainconfig.server_id
|
||||||
|
|
||||||
|
this.maxage = (parseInt(this.config.maxage, 10) || 0) * 1000
|
||||||
this.url = URL.parse(this.config.url)
|
this.url = URL.parse(this.config.url)
|
||||||
if (this.url.hostname === 'registry.npmjs.org') {
|
if (this.url.hostname === 'registry.npmjs.org') {
|
||||||
// npm registry is too slow working with ssl :(
|
// npm registry is too slow working with ssl :(
|
||||||
|
|
Loading…
Add table
Reference in a new issue