UserAnalyticsIdCache.js 631 B

123456789101112131415161718192021222324252627
  1. const UserGetter = require('../User/UserGetter')
  2. const { CacheLoader } = require('cache-flow')
  3. const { getAnalyticsIdFromMongoUser } = require('./AnalyticsHelper')
  4. class UserAnalyticsIdCache extends CacheLoader {
  5. constructor() {
  6. super('user-analytics-id', {
  7. expirationTime: 60,
  8. maxSize: 10000,
  9. })
  10. }
  11. async load(userId) {
  12. const user = await UserGetter.promises.getUser(userId, { analyticsId: 1 })
  13. if (user) {
  14. return getAnalyticsIdFromMongoUser(user)
  15. }
  16. }
  17. keyToString(userId) {
  18. if (userId) {
  19. return userId.toString()
  20. }
  21. }
  22. }
  23. module.exports = new UserAnalyticsIdCache()