From 0abc856ce9b0070b74ee01b8faad2982f60828f6 Mon Sep 17 00:00:00 2001 From: travis Date: Tue, 17 Mar 2020 10:55:08 +0800 Subject: [PATCH] avoid multiple update db process --- core.js | 55 ++++++++++++++++++++++++++----------------------- source/curse.js | 3 ++- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/core.js b/core.js index ab26e5f..98afdd5 100644 --- a/core.js +++ b/core.js @@ -239,8 +239,10 @@ function batchInstall(aa, update, done) { let core = { add(aa, done) { - log('\nInstalling addon' + (aa.length > 1 ? 's...' : '...') + '\n') - batchInstall(aa.map(x => api.parseName(x)), 0, done) + api.getDB(db => { + log('\nInstalling addon' + (aa.length > 1 ? 's...' : '...') + '\n') + batchInstall(aa.map(x => api.parseName(x)), 0, done) + }) }, rm(keys, done) { @@ -414,33 +416,34 @@ let core = { }, update(keys, opt, done) { - if (opt.db) return api.getDB() + api.getDB(db => { + if (opt.db) return + + let aa = [] + if (!keys) keys = _.keys(ads.data) + + keys.forEach(k => { + if (k in ads.data) + aa.push({ + key: k, + source: ads.data[k].source, + anyway: ads.data[k].anyway && cfg.anyway(), + branch: ads.data[k].branch, + uri: ads.data[k].uri, + hash: ads.data[k].hash, + pin: ads.data[k].pin + }) + }) - let aa = [] - if (!keys) keys = _.keys(ads.data) + if (!aa.length) { + log('\nnothing to update\n') + return + } - keys.forEach(k => { - if (k in ads.data) - aa.push({ - key: k, - source: ads.data[k].source, - anyway: ads.data[k].anyway && cfg.anyway(), - branch: ads.data[k].branch, - uri: ads.data[k].uri, - hash: ads.data[k].hash, - pin: ads.data[k].pin - }) + if (ads.checkDuplicate()) return + log('\nUpdating addons:\n') + batchInstall(aa, 1, done) }) - - if (!aa.length) { - log('\nnothing to update\n') - return - } - - if (ads.checkDuplicate()) return - - log('\nUpdating addons:\n') - batchInstall(aa, 1, done) }, restore(repo, done) { diff --git a/source/curse.js b/source/curse.js index 2d8523d..d44eeeb 100644 --- a/source/curse.js +++ b/source/curse.js @@ -83,7 +83,8 @@ let api = { done(JSON.parse(res.body)) }) .catch(err => { - log('githubcontent error', err) + log('require curse db failed', err.toString()) + process.exit(1) done() }) },