Merge pull request #4639 from overleaf/ab-web-mono-analytics-id
Analytics ID support GitOrigin-RevId: 820a6c0f4d19f046f6c791ce4dc64dbc80748924
This commit is contained in:
committed by
Copybot
parent
8ec01f59da
commit
6dd641e0e6
@@ -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()
|
||||
Reference in New Issue
Block a user