-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: resolve jsonurls while merging reports #499
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
'use strict'; | ||
|
||
const axios = require('axios'); | ||
const _ = require('lodash'); | ||
const serverUtils = require('../server-utils'); | ||
|
||
module.exports = async (pluginConfig, hermione, srcPaths, {destination: destPath}) => { | ||
validateOpts(srcPaths, destPath); | ||
|
||
const resolvedUrls = await tryResolveUrls(srcPaths); | ||
|
||
await Promise.all([ | ||
serverUtils.saveStaticFilesToReportDir(hermione.htmlReporter, pluginConfig, destPath), | ||
serverUtils.writeDatabaseUrlsFile(destPath, srcPaths) | ||
serverUtils.writeDatabaseUrlsFile(destPath, resolvedUrls) | ||
]); | ||
|
||
await hermione.htmlReporter.emitAsync(hermione.htmlReporter.events.REPORT_SAVED, {reportPath: destPath}); | ||
|
@@ -22,3 +26,42 @@ function validateOpts(srcPaths, destPath) { | |
throw new Error(`Destination report path: ${destPath}, exists in source report paths`); | ||
} | ||
} | ||
|
||
async function tryResolveUrls(urls) { | ||
const resolvedUrls = []; | ||
const results = await Promise.all(urls.map(tryResolveUrl)); | ||
|
||
results.forEach(({jsonUrls, dbUrls}) => { | ||
resolvedUrls.push(...jsonUrls.concat(dbUrls)); | ||
}); | ||
|
||
return resolvedUrls; | ||
} | ||
|
||
async function tryResolveUrl(url) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Рекурсивно проходит по всем вложенным .json базам. Если возникает ошибка при получении данных, возвращаем саму json-базу. Помимо "ничего не сломать", фоллбэк нужен для драфт отчетов |
||
const jsonUrls = []; | ||
const dbUrls = []; | ||
|
||
if (serverUtils.isDbUrl(url)) { | ||
dbUrls.push(url); | ||
} else if (serverUtils.isJsonUrl(url)) { | ||
try { | ||
const {data} = await axios.get(url); | ||
const currentDbUrls = _.get(data, 'dbUrls', []); | ||
const currentJsonUrls = _.get(data, 'jsonUrls', []); | ||
|
||
const responses = await Promise.all(currentJsonUrls.map(tryResolveUrl)); | ||
|
||
dbUrls.push(...currentDbUrls); | ||
|
||
responses.forEach(response => { | ||
dbUrls.push(...response.dbUrls); | ||
jsonUrls.push(...response.jsonUrls); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. для чего нам здесь накапливать json-урлы? просто на всякий случай, чтобы понять откуда базы приехали? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нет, тут логика такая: в Эта же функция берет |
||
}); | ||
} catch (e) { | ||
jsonUrls.push(url); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. у нас разве где-то есть проверка на то, что мы можем передать только путы формата json/db? сейчас у тебя нет обработки на такой случай и мы вернем пустые массивы. Это вроде и норм, но ругнуться все равно на это нужно There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
return {jsonUrls, dbUrls}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Все urls вставляются в один массив, потому что это позволяет не ломать API слияния отчетов