add isComplete column to response model for better sanity checking

This commit is contained in:
2025-07-06 15:09:13 +00:00
parent cbf6b1d3eb
commit 3466a984ac
4 changed files with 25 additions and 2 deletions

View File

@ -0,0 +1,19 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Response" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"pleromaNotificationId" TEXT NOT NULL DEFAULT 'null',
"to" TEXT NOT NULL DEFAULT 'null',
"request" TEXT NOT NULL DEFAULT 'null',
"response" TEXT NOT NULL DEFAULT 'null',
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"processedAt" DATETIME,
"isProcessing" BOOLEAN NOT NULL DEFAULT true,
"isComplete" BOOLEAN NOT NULL DEFAULT true
);
INSERT INTO "new_Response" ("createdAt", "id", "isProcessing", "pleromaNotificationId", "processedAt", "request", "response", "to") SELECT "createdAt", "id", "isProcessing", "pleromaNotificationId", "processedAt", "request", "response", "to" FROM "Response";
DROP TABLE "Response";
ALTER TABLE "new_Response" RENAME TO "Response";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@ -20,6 +20,7 @@ model Response {
createdAt DateTime @default(now()) createdAt DateTime @default(now())
processedAt DateTime? processedAt DateTime?
isProcessing Boolean @default(true) isProcessing Boolean @default(true)
isComplete Boolean @default(true)
} }
model User { model User {

View File

@ -14,6 +14,7 @@ const storePromptData = async (
request: trimInputData(notification.status.content), request: trimInputData(notification.status.content),
to: notification.account.fqn, to: notification.account.fqn,
isProcessing: false, isProcessing: false,
isComplete: true,
}, },
}); });
} catch (error: any) { } catch (error: any) {

View File

@ -17,6 +17,8 @@ const recordPendingResponse = async (notification: Notification) => {
await prisma.response.create({ await prisma.response.create({
data: { data: {
pleromaNotificationId: notification.id, pleromaNotificationId: notification.id,
isProcessing: true,
isComplete: false,
}, },
}); });
} catch (error: any) { } catch (error: any) {
@ -49,9 +51,9 @@ const alreadyRespondedTo = async (
): Promise<boolean> => { ): Promise<boolean> => {
try { try {
const duplicate = await prisma.response.findFirst({ const duplicate = await prisma.response.findFirst({
where: { pleromaNotificationId: notification.id, isProcessing: true }, where: { pleromaNotificationId: notification.id },
}); });
if (duplicate) { if (duplicate?.isProcessing || duplicate?.isComplete) {
return true; return true;
} }
return false; return false;