5c5a01777c
* Making getAnalyticsIdFromMongoUser private to UserAnalyticsIdCache * renaming userAnalyticsIdCache to UserAnalyticsIdCache * deleting function _getAnalyticsIdFromMongoUser * renaming userAnalyticsIdCache to UserAnalyticsIdCache part 2 * format:fix * adding upperCamelCase * capital case first letter GitOrigin-RevId: 2e9c18c544b8cffb53838aed56e1ef16979606a5
32 lines
768 B
JavaScript
32 lines
768 B
JavaScript
const UserGetter = require('../User/UserGetter')
|
|
const { CacheLoader } = require('cache-flow')
|
|
const { callbackify } = require('util')
|
|
|
|
class UserAnalyticsIdCache extends CacheLoader {
|
|
constructor() {
|
|
super('user-analytics-id', {
|
|
expirationTime: 60,
|
|
maxSize: 10000,
|
|
})
|
|
}
|
|
|
|
async load(userId) {
|
|
const user = await UserGetter.promises.getUser(userId, { analyticsId: 1 })
|
|
if (user) {
|
|
return user.analyticsId || user._id.toString()
|
|
}
|
|
}
|
|
|
|
keyToString(userId) {
|
|
if (userId) {
|
|
return userId.toString()
|
|
}
|
|
}
|
|
}
|
|
|
|
const userAnalyticsIdCache = new UserAnalyticsIdCache()
|
|
userAnalyticsIdCache.callbacks = {
|
|
get: callbackify(userAnalyticsIdCache.get).bind(userAnalyticsIdCache),
|
|
}
|
|
module.exports = userAnalyticsIdCache
|