Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Fix record merging #84

Merged
merged 1 commit into from
Apr 27, 2017
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
21 changes: 8 additions & 13 deletions client/recordUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,19 @@ const mergeRecord = (record1, record2) => {
* @returns {Array}
*/
const mergeRecords = (recordsAndObjects) => {
let idsAndIndices = {}
let outputList = []
for (let n = 0; n < recordsAndObjects.length; n++) {
const recordAndObject = recordsAndObjects[n]
const objectIdMap = {} // map of objectId to [record, object]
recordsAndObjects.forEach((recordAndObject) => {
const record = recordAndObject[0]
const object = recordAndObject[1]
const id = JSON.stringify(record.objectId)
const previousIndex = idsAndIndices[id]
if (previousIndex >= 0) {
const previousRecord = recordsAndObjects[previousIndex][0]
const mergedRecord = mergeRecord(previousRecord, record)
outputList[previousIndex] = [mergedRecord, object]
if (objectIdMap[id]) {
const mergedRecord = mergeRecord(objectIdMap[id][0], record)
objectIdMap[id] = [mergedRecord, object]
} else {
idsAndIndices[id] = outputList.length
outputList.push(recordAndObject)
objectIdMap[id] = recordAndObject
}
}
return outputList
})
return Object.values(objectIdMap)
}

/**
Expand Down