Skip to content

Commit

Permalink
Fix merge id normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 9, 2022
1 parent 0fed3cc commit 66534fd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/history/merge/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export const isValidId = function (value) {

// `merge` can be "last", which refers to the previous result's id.
// If there are no previous results, a new UUIDv4 is generated.
export const normalizeId = function (targetResult, history) {
if (targetResult.id !== LAST_ID) {
return targetResult
export const normalizeId = function (newResult, history) {
if (newResult.id !== LAST_ID) {
return newResult
}

const id =
history.length === 0 ? getDefaultId() : history[history.length - 1].id
return { ...targetResult, id }
return { ...newResult, id }
}

const LAST_ID = 'last'
Expand Down
5 changes: 1 addition & 4 deletions src/history/merge/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { mergeSystems } from '../../top/system/merge.js'
import { groupBy } from '../../utils/group.js'
import { pickLast } from '../../utils/last.js'

import { normalizeId } from './id.js'

// Merge all rawResults with the same `id`.
// The `merge` configuration property sets the result's `id`, which can be used
// to merge several results.
Expand Down Expand Up @@ -58,9 +56,8 @@ import { normalizeId } from './id.js'
// - However, grouping can remove this sorting order, so we sort again to
// ensure the last result is still the target result
export const mergeResults = function (history, targetResult) {
const targetResultA = normalizeId(targetResult, history)
const rawResultsGroups = Object.values(
groupBy([...history, targetResultA], 'id'),
groupBy([...history, targetResult], 'id'),
)
const results = rawResultsGroups.map(mergeRawResultsGroup)
const resultsA = sortOn(results, 'timestamp')
Expand Down
4 changes: 3 additions & 1 deletion src/run/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { listCombinations } from '../combination/list.js'
import { listHistory } from '../history/data/main.js'
import { normalizeId } from '../history/merge/id.js'
import { createTopProps } from '../top/create.js'

// Create a newResult to measure
Expand All @@ -8,7 +9,8 @@ export const createResult = async function (config) {
createNewResult(config),
listHistory(config),
])
return { newResult, history }
const newResultA = normalizeId(newResult, history)
return { newResult: newResultA, history }
}

const createNewResult = async function (config) {
Expand Down

0 comments on commit 66534fd

Please sign in to comment.