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