Skip to content

Commit

Permalink
Remove incSearchCount code
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaapple committed Jan 10, 2025
1 parent 5ec8dd6 commit a6b9b05
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 93 deletions.
16 changes: 2 additions & 14 deletions frontend/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export const RATE_LIMIT_KEY = 'ratelimit';
export const URLS_KEY = 'urls:';
export const ERROR_URLS_KEY = 'error_urls:';
export const INDEX_COUNT_KEY = 'index_count:';
export const TOTAL_INDEX_COUNT_KEY = 't_index_count:';

export const SEARCH_COUNT_KEY = 's_count:';
export const TOTAL_SEARCH_COUNT_KEY = 't_s_count:';

export const redisDB = new Redis({
url: UPSTASH_REDIS_REST_URL!,
Expand Down Expand Up @@ -62,13 +58,6 @@ export async function getUserIdByEmail(email: string) {
}
}

export async function incSearchCount(userId: string): Promise<void> {
if (!userId) {
userId = 'guest';
}
const result = await Promise.all([redisDB.incr(SEARCH_COUNT_KEY + userId), redisDB.incr(TOTAL_SEARCH_COUNT_KEY)]);
}

export async function removeUrlFromErrorUrls(userId: string, url: string) {
const result = await redisDB.zrem(ERROR_URLS_KEY + userId, url);
console.log('removeUrlFromErrorUrls:', result);
Expand Down Expand Up @@ -124,13 +113,12 @@ export async function getUserIndexCount(userId: string): Promise<number> {

export async function addUrl(userId: string, url: string): Promise<number> {
const date = Date.now();
const [zaddResult, incrIndexCountResult, incrTotalIndexCountResult] = await Promise.all([
const [zaddResult, incrIndexCountResult] = await Promise.all([
redisDB.zadd(URLS_KEY + userId, { score: date, member: url }),
redisDB.incr(INDEX_COUNT_KEY + userId),
redisDB.incr(TOTAL_INDEX_COUNT_KEY),
]);

console.log('Result of all operations:', zaddResult, incrIndexCountResult, incrTotalIndexCountResult);
console.log('Result of all operations:', zaddResult, incrIndexCountResult);
return incrIndexCountResult;
}

Expand Down
5 changes: 0 additions & 5 deletions frontend/lib/tools/auto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'server-only';

import { incSearchCount } from '@/lib/db';
import { convertToCoreMessages, getLLM, getMaxOutputToken } from '@/lib/llm/llm';
import { AutoAnswerPrompt } from '@/lib/llm/prompt';
import { getHistory, getHistoryMessages, streamResponse } from '@/lib/llm/utils';
Expand Down Expand Up @@ -271,10 +270,6 @@ export async function autoAnswer(
await streamResponse({ title: title }, onStream);
}

// incSearchCount(userId).catch((error) => {
// console.error(`Failed to increment search count for user ${userId}:`, error);
// });

await saveMessages(userId, messages, fullAnswer, texts, images, videos, fullRelated, SearchCategory.ALL);
indexMessage(userId, messages[0].title, messages[0].id, query + '\n\n' + fullAnswer).catch((error) => {
console.error(`Failed to index message for user ${userId}:`, error);
Expand Down
4 changes: 0 additions & 4 deletions frontend/lib/tools/chat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'server-only';

import { incSearchCount } from '@/lib/db';
import { convertToCoreMessages, getLLM, getMaxOutputToken } from '@/lib/llm/llm';
import { ChatPrompt } from '@/lib/llm/prompt';
import { getHistoryMessages, streamResponse } from '@/lib/llm/utils';
Expand Down Expand Up @@ -71,9 +70,6 @@ export async function chat(
await streamResponse({ title: title }, onStream);
}

// incSearchCount(userId).catch((error) => {
// console.error(`Failed to increment search count for user ${userId}:`, error);
// });
await saveMessages(userId, messages, fullAnswer, [], [], [], '', SearchCategory.ALL);
indexMessage(userId, messages[0].title, messages[0].id, query + '\n\n' + fullAnswer).catch((error) => {
console.error(`Failed to index message for user ${userId}:`, error);
Expand Down
5 changes: 0 additions & 5 deletions frontend/lib/tools/generate-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { log, logError } from '@/lib/log';
import { streamText } from 'ai';
import { SearchCategory, Message as StoreMessage } from '@/lib/types';
import { Claude_35_Sonnet } from '@/lib/model';
import { incSearchCount } from '@/lib/db';
import { extractErrorMessage, saveMessages } from '@/lib/server-utils';
import { getSearchEngine, TEXT_LIMIT } from '@/lib/search/search';
import util from 'util';
Expand Down Expand Up @@ -107,10 +106,6 @@ export async function generateUI(
onStream?.(JSON.stringify({ answer: text }));
}

// incSearchCount(userId).catch((error) => {
// console.error(`Failed to increment search count for user ${userId}:`, error);
// });

await saveMessages(userId, messages, fullAnswer, [], [], [], '', SearchCategory.UI);
} catch (error) {
const errorMessage = extractErrorMessage(error);
Expand Down
5 changes: 0 additions & 5 deletions frontend/lib/tools/indie.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'server-only';

import { incSearchCount } from '@/lib/db';
import { getLLM } from '@/lib/llm/llm';
import { getHistory, streamResponse } from '@/lib/llm/utils';
import { logError } from '@/lib/log';
Expand Down Expand Up @@ -102,10 +101,6 @@ export async function indieMakerSearch(
);
});

// incSearchCount(userId).catch((error) => {
// console.error(`Failed to increment search count for user ${userId}:`, error);
// });

await saveMessages(userId, messages, fullAnswer, texts, images, videos, fullRelated);
onStream?.(null, true);
} catch (error) {
Expand Down
5 changes: 0 additions & 5 deletions frontend/lib/tools/knowledge-base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'server-only';

import { incSearchCount } from '@/lib/db';
import { getLLM } from '@/lib/llm/llm';
import { getHistory, streamResponse } from '@/lib/llm/utils';
import { logError } from '@/lib/log';
Expand Down Expand Up @@ -66,10 +65,6 @@ export async function knowledgeBaseSearch(messages: StoreMessage[], isPro: boole
return;
}

// incSearchCount(userId).catch((error) => {
// console.error(`Failed to increment search count for user ${userId}:`, error);
// });

await saveMessages(userId, messages, fullAnswer, texts, [], [], '');
onStream?.(null, true);
} catch (error) {
Expand Down
5 changes: 0 additions & 5 deletions frontend/lib/tools/o1-answer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'server-only';

import { incSearchCount } from '@/lib/db';
import { getLLM } from '@/lib/llm/llm';
import { DirectAnswerPrompt } from '@/lib/llm/prompt';
import { getHistoryMessages, streamResponse } from '@/lib/llm/utils';
Expand Down Expand Up @@ -89,10 +88,6 @@ export async function o1Answer(
await streamResponse({ videos: videos }, onStream);
}

incSearchCount(userId).catch((error) => {
console.error(`Failed to increment search count for user ${userId}:`, error);
});

await saveMessages(userId, messages, fullAnswer, texts, images, videos, fullRelated);
onStream?.(null, true);
} catch (error) {
Expand Down
5 changes: 0 additions & 5 deletions frontend/lib/tools/product.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'server-only';

import { incSearchCount } from '@/lib/db';
import { getLLM } from '@/lib/llm/llm';
import { getHistory, streamResponse } from '@/lib/llm/utils';
import { logError } from '@/lib/log';
Expand Down Expand Up @@ -99,10 +98,6 @@ export async function productSearch(
);
});

// incSearchCount(userId).catch((error) => {
// console.error(`Failed to increment search count for user ${userId}:`, error);
// });

await saveMessages(userId, messages, fullAnswer, texts, images, videos, fullRelated);
onStream?.(null, true);
} catch (error) {
Expand Down
51 changes: 6 additions & 45 deletions vector/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export const redis = new Redis({
export const URLS_KEY = "urls:";
export const ERROR_URLS_KEY = "error_urls:";
export const INDEX_COUNT_KEY = "index_count:";
export const TOTAL_INDEX_COUNT_KEY = "t_index_count:";

export const SEARCH_COUNT_KEY = "s_count:";
export const TOTAL_SEARCH_COUNT_KEY = "t_s_count:";

export const SEARCH_KEY = "search:";
export const USER_SEARCH_KEY = "user:search:";
Expand Down Expand Up @@ -54,19 +50,12 @@ export async function markUserFullIndexed(userId: string): Promise<void> {

export async function addUrl(userId: string, url: string): Promise<number> {
const date = Date.now();
const [zaddResult, incrIndexCountResult, incrTotalIndexCountResult] =
await Promise.all([
redis.zadd(URLS_KEY + userId, { score: date, member: url }),
redis.incr(INDEX_COUNT_KEY + userId),
redis.incr(TOTAL_INDEX_COUNT_KEY),
]);

console.log(
"Result of all operations:",
zaddResult,
incrIndexCountResult,
incrTotalIndexCountResult
);
const [zaddResult, incrIndexCountResult] = await Promise.all([
redis.zadd(URLS_KEY + userId, { score: date, member: url }),
redis.incr(INDEX_COUNT_KEY + userId),
]);

console.log("Result of all operations:", zaddResult, incrIndexCountResult);
return incrIndexCountResult;
}

Expand Down Expand Up @@ -96,31 +85,3 @@ export async function urlExists(userId: string, url: string): Promise<boolean> {
export async function clearUrls(userId: string): Promise<void> {
await redis.del(URLS_KEY + userId);
}

async function getCount(key: string): Promise<number> {
const value = await redis.get(key);
return parseInt((value as string) || "0", 10);
}

export async function incIndexCount(userId: string): Promise<void> {
const result = await Promise.all([
redis.incr(INDEX_COUNT_KEY + userId),
redis.incr(TOTAL_INDEX_COUNT_KEY),
]);
}

export async function getIndexCount(userId: string): Promise<number> {
return getCount(INDEX_COUNT_KEY + userId);
}

export async function getTotalIndexCount(): Promise<number> {
return getCount(TOTAL_INDEX_COUNT_KEY);
}

export async function getSearchCount(userId: string): Promise<number> {
return getCount(SEARCH_COUNT_KEY + userId);
}

export async function getTotalSearchCount(): Promise<number> {
return getCount(TOTAL_SEARCH_COUNT_KEY);
}

0 comments on commit a6b9b05

Please sign in to comment.