Skip to content

Commit

Permalink
fix(channel-web): fix users caching
Browse files Browse the repository at this point in the history
  • Loading branch information
emirotin authored and epaminond committed Sep 27, 2018
1 parent 02183cd commit c56ceb0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/channels/botpress-channel-web/src/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ module.exports = async bp => {

if (!user) {
try {
user = createNewUser(userId)
user = await createNewUser(userId)
} catch (err) {
bp.logger.error(err.message, err.stack)
throw new Error(`User ${userId} not found`)
}
}

if (!user) {
throw new Error(`User ${userId} not found`)
}

knownUsersCache.set(userId, user)
return user
}
Expand All @@ -71,12 +75,7 @@ module.exports = async bp => {
}

const ensureUserExists = async userId => {
userId = sanitizeUserId(userId)
if (knownUsersCache.has(userId)) {
return
}
await getOrCreateUser(userId)
knownUsersCache.set(userId, true)
}

return { getOrCreateUser, getUserProfile, ensureUserExists }
Expand Down

0 comments on commit c56ceb0

Please sign in to comment.