fix(danisman): M2 (6) — 100 mesajı aşan geçmişte en yeni 100 dönsün
sohbetGecmisiGetir yeniden eskiye sıralayıp 100 alır, sonra çevirir; aynı saniyedeki soru-cevap sırası rowid ile korunur. GET /api/soru da aynı sorguyu kullanır (iki kopya vardı). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import "server-only";
|
||||
import { asc, eq } from "drizzle-orm";
|
||||
import { desc, eq, sql } from "drizzle-orm";
|
||||
import { appDb, schema } from "@/lib/appdb";
|
||||
import { anahtarVar } from "@/lib/ai/client";
|
||||
import type { RaporSonuc } from "./types/rapor";
|
||||
@@ -40,9 +40,13 @@ export async function kullanicininRaporu(userId: string) {
|
||||
return satir ?? null;
|
||||
}
|
||||
|
||||
/** Kullanıcının danışman sohbet geçmişi, eskiden yeniye (en fazla 100 mesaj). */
|
||||
export function sohbetGecmisiGetir(userId: string) {
|
||||
return appDb
|
||||
/**
|
||||
* Kullanıcının danışman sohbet geçmişi: en YENİ 100 mesaj, eskiden yeniye.
|
||||
* created_at saniye çözünürlüklü; aynı saniyedeki soru-cevap sırası rowid ile
|
||||
* korunur.
|
||||
*/
|
||||
export async function sohbetGecmisiGetir(userId: string) {
|
||||
const satirlar = await appDb
|
||||
.select({
|
||||
id: schema.chatMessages.id,
|
||||
role: schema.chatMessages.role,
|
||||
@@ -50,6 +54,7 @@ export function sohbetGecmisiGetir(userId: string) {
|
||||
})
|
||||
.from(schema.chatMessages)
|
||||
.where(eq(schema.chatMessages.userId, userId))
|
||||
.orderBy(asc(schema.chatMessages.createdAt))
|
||||
.orderBy(desc(schema.chatMessages.createdAt), sql`rowid DESC`)
|
||||
.limit(100);
|
||||
return satirlar.reverse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user