💚 Fix cleanDatabase when deleting more than 100,000 sessions
This commit is contained in:
@ -68,6 +68,8 @@ const deleteArchivedResults = async () => {
|
||||
const deleteOldChatSessions = async () => {
|
||||
const twoDaysAgo = new Date()
|
||||
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2)
|
||||
let totalChatSessions
|
||||
do {
|
||||
const chatSessions = await prisma.chatSession.findMany({
|
||||
where: {
|
||||
updatedAt: {
|
||||
@ -77,8 +79,11 @@ const deleteOldChatSessions = async () => {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
take: 80000,
|
||||
})
|
||||
|
||||
totalChatSessions = chatSessions.length
|
||||
|
||||
console.log(`Deleting ${chatSessions.length} old chat sessions...`)
|
||||
const chunkSize = 1000
|
||||
for (let i = 0; i < chatSessions.length; i += chunkSize) {
|
||||
@ -91,6 +96,7 @@ const deleteOldChatSessions = async () => {
|
||||
},
|
||||
})
|
||||
}
|
||||
} while (totalChatSessions === 80000)
|
||||
}
|
||||
|
||||
const deleteExpiredAppSessions = async () => {
|
||||
|
Reference in New Issue
Block a user