Skip to content

Commit

Permalink
Allow several stores at once
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 11, 2019
1 parent 1152ddf commit 14e299f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/save/find.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { STORES } from './stores/main.js'

// Find the store according to the `stores` option
export const findStore = function() {
return STORES.file
// Find the stores according to the `stores` and `data` options.
// Several stores can be used at once when saving, but only one when loading.
export const findStores = function() {
return [STORES.file]
}
25 changes: 15 additions & 10 deletions src/save/main.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { omitBy } from '../utils/main.js'

import { findStore } from './find.js'
import { findStores } from './find.js'

// Save benchmark results so they can be compared or shown later
export const save = async function(benchmark, { save: saveOpt, dataDir }) {
if (!saveOpt) {
return
}

const store = findStore()

const benchmarkA = normalizeBenchmark(benchmark)

try {
await store.add(dataDir, benchmarkA)
} catch (error) {
throw new Error(
`Could not save benchmark to '${dataDir}':\n\n${error.stack}`,
)
}
const stores = findStores()
await Promise.all(
stores.map(store => saveToStore(store, dataDir, benchmarkA)),
)
}

// Some benchmark information are not persisted:
Expand All @@ -40,3 +35,13 @@ const removeBigStats = function(stats) {
}

const OMITTED_STATS_PROPS = ['histogram', 'percentiles']

const saveToStore = async function(store, dataDir, benchmark) {
try {
await store.add(dataDir, benchmark)
} catch (error) {
throw new Error(
`Could not save benchmark to '${dataDir}':\n\n${error.stack}`,
)
}
}

0 comments on commit 14e299f

Please sign in to comment.