more debugging logs

This commit is contained in:
Hongbo Wu
2024-08-14 13:04:29 +08:00
parent 8b9ab287d7
commit c9aa90b3ae
4 changed files with 30 additions and 1 deletions

View File

@ -206,6 +206,8 @@ export const userDigestEligible = async (uid: string): Promise<boolean> => {
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,

View File

@ -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)
}

View File

@ -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),

View File

@ -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<Shortcut[]> => {
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),