format string LowerCase and replace spaces
This commit is contained in:
parent
c7f74e2359
commit
737eaa0b3c
1 changed files with 11 additions and 3 deletions
|
|
@ -29,7 +29,11 @@ type WSMessage = {
|
||||||
focusMode: string;
|
focusMode: string;
|
||||||
history: Array<[string, string]>;
|
history: Array<[string, string]>;
|
||||||
};
|
};
|
||||||
|
const formatString = (str: string) => {
|
||||||
|
let lowerCased = str.toLowerCase();
|
||||||
|
let formatted = lowerCased.trim().replace(/\s+/g, ' ');
|
||||||
|
return formatted;
|
||||||
|
};
|
||||||
const searchHandlers = {
|
const searchHandlers = {
|
||||||
webSearch: handleWebSearch,
|
webSearch: handleWebSearch,
|
||||||
academicSearch: handleAcademicSearch,
|
academicSearch: handleAcademicSearch,
|
||||||
|
|
@ -101,7 +105,11 @@ const handleEmitterEvents = (
|
||||||
metadata: JSON.stringify(sources),
|
metadata: JSON.stringify(sources),
|
||||||
};
|
};
|
||||||
await redisClient
|
await redisClient
|
||||||
.setEx(cacheKey, 86400, JSON.stringify(responseWithSources))
|
.setEx(
|
||||||
|
formatString(cacheKey),
|
||||||
|
86400,
|
||||||
|
JSON.stringify(responseWithSources),
|
||||||
|
)
|
||||||
.then(() => logger.info(`Cache set for ${cacheKey}`))
|
.then(() => logger.info(`Cache set for ${cacheKey}`))
|
||||||
.catch((err) => logger.error(`Redis setEx error: ${err}`));
|
.catch((err) => logger.error(`Redis setEx error: ${err}`));
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +151,7 @@ export const handleMessage = async (
|
||||||
const shouldCache = parsedMessage.cache === '1';
|
const shouldCache = parsedMessage.cache === '1';
|
||||||
|
|
||||||
if (shouldCache) {
|
if (shouldCache) {
|
||||||
const cachedResponse = await redisClient.get(cacheKey);
|
const cachedResponse = await redisClient.get(formatString(cacheKey));
|
||||||
|
|
||||||
if (cachedResponse) {
|
if (cachedResponse) {
|
||||||
const jsonDatabase = JSON.parse(cachedResponse);
|
const jsonDatabase = JSON.parse(cachedResponse);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue