aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/api
diff options
context:
space:
mode:
authorDhravya Shah <[email protected]>2024-07-25 18:58:28 -0500
committerGitHub <[email protected]>2024-07-25 18:58:28 -0500
commit417872c936e8a84f76e2833387c488660e18c094 (patch)
treec6f7aca777c7f4748cc6dc335fe56fba8725af02 /apps/web/app/api
parentughh, regenerated migrations. my bad. (diff)
parentsolve merge conflicts (diff)
downloadsupermemory-417872c936e8a84f76e2833387c488660e18c094.tar.xz
supermemory-417872c936e8a84f76e2833387c488660e18c094.zip
Merge pull request #140 from supermemoryai/kush/experimental-thread
support threads and segregate chunks
Diffstat (limited to 'apps/web/app/api')
-rw-r--r--apps/web/app/api/chat/route.ts26
-rw-r--r--apps/web/app/api/store/route.ts7
2 files changed, 19 insertions, 14 deletions
diff --git a/apps/web/app/api/chat/route.ts b/apps/web/app/api/chat/route.ts
index 9127261c..a14c96df 100644
--- a/apps/web/app/api/chat/route.ts
+++ b/apps/web/app/api/chat/route.ts
@@ -48,22 +48,22 @@ export async function POST(req: NextRequest) {
// Only allow 5 requests per hour for each user, something lke this but this one is bad because chathistory.userid doesnt exist, we have to do a join and get it from the threads table
const result = await db
- .select({
- count: sql<number>`count(*)`.mapWith(Number),
- })
- .from(chatHistoryDb)
- .innerJoin(chatThreads, eq(chatHistoryDb.threadId, chatThreads.id))
- .where(
- and(
- eq(chatThreads.userId, session.user.id),
- gt(chatHistoryDb.createdAt, lastHour)
- )
- )
- .execute();
+ .select({
+ count: sql<number>`count(*)`.mapWith(Number),
+ })
+ .from(chatHistoryDb)
+ .innerJoin(chatThreads, eq(chatHistoryDb.threadId, chatThreads.id))
+ .where(
+ and(
+ eq(chatThreads.userId, session.user.id),
+ gt(chatHistoryDb.createdAt, lastHour),
+ ),
+ )
+ .execute();
if (result[0]?.count && result[0]?.count >= 5) {
// return new Response(`Too many requests ${result[0]?.count}`, { status: 429 });
- console.log(result[0]?.count)
+ console.log(result[0]?.count);
} else {
console.log("count", result);
}
diff --git a/apps/web/app/api/store/route.ts b/apps/web/app/api/store/route.ts
index da393d2e..992c2a0e 100644
--- a/apps/web/app/api/store/route.ts
+++ b/apps/web/app/api/store/route.ts
@@ -30,7 +30,12 @@ const createMemoryFromAPI = async (input: {
count: sql<number>`count(*)`.mapWith(Number),
})
.from(storedContent)
- .where(and(gt(storedContent.savedAt, last2Hours), eq(storedContent.userId, input.userId)))
+ .where(
+ and(
+ gt(storedContent.savedAt, last2Hours),
+ eq(storedContent.userId, input.userId),
+ ),
+ );
if (numberOfItemsSavedInLast2Hours[0]!.count >= 20) {
return {