From d00a76ca3fc9184d4348db73c77cb02da2723a7e Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 14 Aug 2024 09:26:34 +0800 Subject: [PATCH] hash args in the cache key --- packages/api/src/services/library_item.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)