Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
avoid multiple update db process
Browse files Browse the repository at this point in the history
  • Loading branch information
travis committed Mar 17, 2020
1 parent 4b9aabd commit 0abc856
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
55 changes: 29 additions & 26 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion source/curse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
},
Expand Down

0 comments on commit 0abc856

Please sign in to comment.