diff --git a/packages/api/src/services/library_item.ts b/packages/api/src/services/library_item.ts index e42dcdb9f..3eebe4efd 100644 --- a/packages/api/src/services/library_item.ts +++ b/packages/api/src/services/library_item.ts @@ -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)