diff --git a/packages/api/src/services/features.ts b/packages/api/src/services/features.ts index 28d097ec2..307d3cc59 100644 --- a/packages/api/src/services/features.ts +++ b/packages/api/src/services/features.ts @@ -206,6 +206,8 @@ export const userDigestEligible = async (uid: string): Promise => { const featuresCacheKey = (userId: string) => `cache:features:${userId}` export const getFeaturesCache = async (userId: string) => { + logger.debug('getFeaturesCache', { userId }) + const cachedFeatures = await redisDataSource.redisClient?.get( featuresCacheKey(userId) ) @@ -218,6 +220,9 @@ export const getFeaturesCache = async (userId: string) => { export const setFeaturesCache = async (userId: string, features: Feature[]) => { const value = JSON.stringify(features) + + logger.debug('setFeaturesCache', { userId, value }) + return redisDataSource.redisClient?.set( featuresCacheKey(userId), value, diff --git a/packages/api/src/services/library_item.ts b/packages/api/src/services/library_item.ts index d1d1673e0..9292284fc 100644 --- a/packages/api/src/services/library_item.ts +++ b/packages/api/src/services/library_item.ts @@ -1724,6 +1724,11 @@ const totalCountCacheKey = (userId: string, args: SearchArgs) => { } export const getCachedTotalCount = async (userId: string, args: SearchArgs) => { + logger.debug('Getting cached total count:', { + userId, + args, + }) + const cacheKey = totalCountCacheKey(userId, args) const cachedCount = await redisDataSource.redisClient?.get(cacheKey) if (!cachedCount) { @@ -1739,6 +1744,12 @@ export const setCachedTotalCount = async ( count: number ) => { const cacheKey = totalCountCacheKey(userId, args) + + logger.debug('Setting cached total count:', { + cacheKey, + count, + }) + await redisDataSource.redisClient?.set(cacheKey, count, 'EX', 600) } @@ -1749,6 +1760,10 @@ export const deleteCachedTotalCount = async (userId: string) => { return } - logger.debug('Deleting keys:', keys) + logger.debug('Deleting keys:', { + keys, + userId, + }) + await redisDataSource.redisClient?.del(keys) } diff --git a/packages/api/src/services/user.ts b/packages/api/src/services/user.ts index 3f7ed7d6c..c5dc336b9 100644 --- a/packages/api/src/services/user.ts +++ b/packages/api/src/services/user.ts @@ -161,6 +161,8 @@ export const findUserAndPersonalization = async (id: string) => { const userCacheKey = (id: string) => `cache:user:${id}` export const getCachedUser = async (id: string) => { + logger.debug(`Getting user from cache: ${id}`) + const user = await redisDataSource.redisClient?.get(userCacheKey(id)) if (!user) { return undefined @@ -170,6 +172,8 @@ export const getCachedUser = async (id: string) => { } export const cacheUser = async (user: User) => { + logger.debug(`Caching user: ${user.id}`) + await redisDataSource.redisClient?.set( userCacheKey(user.id), JSON.stringify(user), diff --git a/packages/api/src/services/user_personalization.ts b/packages/api/src/services/user_personalization.ts index 5661d960a..f20afa156 100644 --- a/packages/api/src/services/user_personalization.ts +++ b/packages/api/src/services/user_personalization.ts @@ -4,6 +4,7 @@ import { Subscription, SubscriptionStatus } from '../entity/subscription' import { Shortcut, UserPersonalization } from '../entity/user_personalization' import { redisDataSource } from '../redis_data_source' import { authTrx } from '../repository' +import { logger } from '../utils/logger' import { findLabelsByUserId } from './labels' export const findUserPersonalization = async (userId: string) => { @@ -177,6 +178,8 @@ const userDefaultShortcuts = async (userId: string): Promise => { const shortcutsCacheKey = (userId: string) => `cache:shortcuts:${userId}` export const getShortcutsCache = async (userId: string) => { + logger.debug(`Getting shortcuts from cache: ${userId}`) + const cachedShortcuts = await redisDataSource.redisClient?.get( shortcutsCacheKey(userId) ) @@ -187,6 +190,8 @@ export const getShortcutsCache = async (userId: string) => { } export const cacheShortcuts = async (userId: string, shortcuts: Shortcut[]) => { + logger.debug(`Caching shortcuts: ${userId}`) + await redisDataSource.redisClient?.set( shortcutsCacheKey(userId), JSON.stringify(shortcuts),