skip duplicates when inserting calls and messages

This commit is contained in:
m5r 2021-08-14 01:15:35 +08:00
parent 306febe4d1
commit f628addd80
3 changed files with 3 additions and 2 deletions

View File

@ -35,7 +35,7 @@ const insertMessagesQueue = Queue<Payload>(
}))
.sort((a, b) => a.sentAt.getTime() - b.sentAt.getTime());
await db.message.createMany({ data: sms });
await db.message.createMany({ data: sms, skipDuplicates: true });
},
);

View File

@ -15,6 +15,7 @@ const fetchCallsQueue = Queue<Payload>("api/queue/fetch-calls", async ({ organiz
include: { organization: true },
});
if (!phoneNumber) {
console.log("no phone number found");
return;
}

View File

@ -32,7 +32,7 @@ const insertCallsQueue = Queue<Payload>("api/queue/insert-calls", async ({ calls
}))
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
await db.phoneCall.createMany({ data: phoneCalls });
await db.phoneCall.createMany({ data: phoneCalls, skipDuplicates: true });
});
export default insertCallsQueue;