hash args in the cache key
This commit is contained in:
@ -35,6 +35,7 @@ import { logger } from '../utils/logger'
|
||||
import { parseSearchQuery } from '../utils/search'
|
||||
import { HighlightEvent } from './highlights'
|
||||
import { addLabelsToLibraryItem, LabelEvent } from './labels'
|
||||
import { stringToHash } from '../utils/helpers'
|
||||
|
||||
const columnsToDelete = [
|
||||
'user',
|
||||
@ -704,7 +705,9 @@ export const createSearchQueryBuilder = (
|
||||
}
|
||||
|
||||
export const countLibraryItems = async (args: SearchArgs, userId: string) => {
|
||||
const cacheKey = `countLibraryItems:${userId}:${JSON.stringify(args)}`
|
||||
// hash the arguments to create a unique cache key
|
||||
const argsHash = stringToHash(JSON.stringify(args))
|
||||
const cacheKey = `countLibraryItems:${userId}:${argsHash}`
|
||||
const cachedCount = await redisDataSource.redisClient?.get(cacheKey)
|
||||
if (cachedCount) {
|
||||
return parseInt(cachedCount, 10)
|
||||
|
||||
Reference in New Issue
Block a user