diff --git a/controllers/sync.js b/controllers/sync.js index bf03c5a59..82ba009e8 100644 --- a/controllers/sync.js +++ b/controllers/sync.js @@ -17,6 +17,7 @@ var debug = require('debug')('cnpmjs.org:controllers:sync'); var Log = require('../services/module_log'); var SyncModuleWorker = require('./sync_module_worker'); +var config = require('../config'); exports.sync = function* () { var username = this.user.name || 'anonymous'; @@ -36,6 +37,7 @@ exports.sync = function* () { var options = { publish: publish, noDep: noDep, + syncUpstreamFirst: config.sourceNpmRegistryIsCNpm, }; var logId = yield* SyncModuleWorker.sync(name, username, options); diff --git a/controllers/sync_module_worker.js b/controllers/sync_module_worker.js index 07a424714..98183a1b7 100644 --- a/controllers/sync_module_worker.js +++ b/controllers/sync_module_worker.js @@ -55,6 +55,7 @@ function SyncModuleWorker(options) { this.username = options.username; this.concurrency = options.concurrency || 1; this._publish = options.publish === true; // _publish_on_cnpm + this.syncUpstreamFirst = options.syncUpstreamFirst; this.syncingNames = {}; this.nameMap = {}; @@ -128,7 +129,7 @@ SyncModuleWorker.prototype.start = function () { var that = this; co(function *() { // sync upstream - if (config.sourceNpmRegistryIsCNpm) { + if (that.syncUpstreamFirst) { try { yield* that.syncUpstream(that.startName); } catch (err) { diff --git a/sync/index.js b/sync/index.js index 688583a15..e5232c1e0 100644 --- a/sync/index.js +++ b/sync/index.js @@ -52,9 +52,14 @@ co(function* () { } }); +var syncInterval = ms(config.syncInterval); +var minSyncInterval = ms('5m'); +if (!syncInterval || syncInterval < minSyncInterval) { + syncInterval = minSyncInterval; +} + // the same time only sync once var syncing = false; - var handleSync = co(function* () { debug('mode: %s, syncing: %s', config.syncModel, syncing); if (!syncing) { @@ -79,11 +84,6 @@ var handleSync = co(function* () { if (sync) { handleSync(); - var syncInterval = ms(config.syncInterval); - var minSyncInterval = ms('5m'); - if (!syncInterval || syncInterval < minSyncInterval) { - syncInterval = minSyncInterval; - } setInterval(handleSync, syncInterval); } @@ -116,7 +116,7 @@ var syncDist = co(function* () { if (config.syncDist) { syncDist(); - setInterval(syncDist, ms(config.syncInterval)); + setInterval(syncDist, syncInterval); } else { logger.syncInfo('sync dist disable'); } @@ -149,7 +149,7 @@ var syncPythonDist = co(function* () { if (config.syncPythonDist) { syncPythonDist(); - setInterval(syncPythonDist, ms(config.syncInterval)); + setInterval(syncPythonDist, syncInterval); } else { logger.syncInfo('sync python dist disable'); } diff --git a/sync/sync_all.js b/sync/sync_all.js index e634f9fc8..f60df30eb 100644 --- a/sync/sync_all.js +++ b/sync/sync_all.js @@ -81,6 +81,7 @@ module.exports = function* sync() { name: packages, noDep: true, concurrency: config.syncConcurrency, + syncUpstreamFirst: false, }); Status.init({need: packages.length}, worker); worker.start(); diff --git a/sync/sync_exist.js b/sync/sync_exist.js index 31674ce50..d5cc6e427 100644 --- a/sync/sync_exist.js +++ b/sync/sync_exist.js @@ -88,7 +88,8 @@ module.exports = function* sync() { var worker = new SyncModuleWorker({ username: 'admin', name: packages, - concurrency: config.syncConcurrency + concurrency: config.syncConcurrency, + syncUpstreamFirst: false, }); Status.init({need: packages.length}, worker); worker.start(); diff --git a/sync/sync_popular.js b/sync/sync_popular.js index f2d26b1f6..2510471c3 100644 --- a/sync/sync_popular.js +++ b/sync/sync_popular.js @@ -27,7 +27,8 @@ module.exports = function* syncPopular() { var worker = new SyncModuleWorker({ username: 'admin', name: packages, - concurrency: config.syncConcurrency + concurrency: config.syncConcurrency, + syncUpstreamFirst: false, }); Status.init({need: packages.length}, worker);