Skip to content

Commit

Permalink
Fix Race Condition When Loading DB
Browse files Browse the repository at this point in the history
  • Loading branch information
jaruba committed Jul 18, 2020
1 parent e9c9b6e commit 05e54de
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions server/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,42 +91,25 @@ function loadUserConfig(err, obj) {
}
}

const config = {
loaded: false,
getAll: () => {
if (!config.loaded) {
function init() {
let obj, err

let obj, err

try {
obj = jsonfile.readFileSync(configPath)
} catch(e) {
err = e
}
try {
obj = jsonfile.readFileSync(configPath)
} catch(e) {
err = e
}

map = loadUserConfig(err, obj)
map = loadUserConfig(err, obj)
}

config.loaded = true
init()

}
const config = {
getAll: () => {
return map
},
get: str => {
if (!config.loaded) {

let obj, err

try {
obj = jsonfile.readFileSync(configPath)
} catch(e) {
err = e
}

map = loadUserConfig(err, obj)

config.loaded = true

}
return map[str]
},
set: (str, value) => {
Expand Down

0 comments on commit 05e54de

Please sign in to comment.