Merge pull request #4639 from overleaf/ab-web-mono-analytics-id

Analytics ID support

GitOrigin-RevId: 820a6c0f4d19f046f6c791ce4dc64dbc80748924
This commit is contained in:
Alexandre Bourdin
2021-09-10 08:04:31 +00:00
committed by Copybot
parent 8ec01f59da
commit 6dd641e0e6
36 changed files with 556 additions and 248 deletions
@@ -0,0 +1,26 @@
const UserGetter = require('../User/UserGetter')
const { CacheLoader } = require('cache-flow')
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
}
}
keyToString(userId) {
if (userId) {
return userId.toString()
}
}
}
module.exports = new UserAnalyticsIdCache()