Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions packages/server/src/services/export-import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,21 @@ async function replaceDuplicateIdsForChatMessage(
})
if (records.length < 0) return originalData

// replace duplicate ids found in db to new id
// Replace duplicate ChatMessage ids found in db with new ids,
// and update corresponding messageId references in ChatMessageFeedback
const idMap: { [key: string]: string } = {}
const dbExistingIds = new Set(records.map((record) => record.id))
originalData.ChatMessage = originalData.ChatMessage.map((item) => {
if (dbExistingIds.has(item.id)) {
return { ...item, id: uuidv4() }
const newId = uuidv4()
idMap[item.id] = newId
return { ...item, id: newId }
}
return item
})
originalData.ChatMessageFeedback = originalData.ChatMessageFeedback.map((item) => {
if (idMap[item.messageId]) {
return { ...item, messageId: idMap[item.messageId] }
}
return item
})
Expand Down Expand Up @@ -408,12 +418,28 @@ async function replaceDuplicateIdsForChatMessageFeedback(
const records = await queryRunner.manager.find(ChatMessageFeedback, {
where: { id: In(ids) }
})

// remove duplicate messageId
const seenMessageIds = new Set()
originalData.ChatMessageFeedback = originalData.ChatMessageFeedback.filter((feedback) => {
if (seenMessageIds.has(feedback.messageId)) {
return false
}
seenMessageIds.add(feedback.messageId)
return true
})

if (records.length < 0) return originalData
for (let record of records) {
const oldId = record.id
const newId = uuidv4()
originalData = JSON.parse(JSON.stringify(originalData).replaceAll(oldId, newId))
}

// replace duplicate ids found in db to new id
const dbExistingIds = new Set(records.map((record) => record.id))
originalData.ChatMessageFeedback = originalData.ChatMessageFeedback.map((item) => {
if (dbExistingIds.has(item.id)) {
const newId = uuidv4()
return { ...item, id: newId }
}
return item
})
return originalData
} catch (error) {
throw new InternalFlowiseError(
Expand Down
Loading