-
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: small js report builder optimization #500
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 |
---|---|---|
|
@@ -58,7 +58,7 @@ export interface Tree { | |
interface ResultPayload { | ||
id: string; | ||
parentId: string; | ||
result: ParsedSuitesRow; | ||
result: Omit<ParsedSuitesRow, 'imagesInfo'>; | ||
} | ||
|
||
interface BrowserPayload { | ||
|
@@ -111,7 +111,7 @@ export class BaseTestsTreeBuilder { | |
|
||
addTestResult(testResult: ParsedSuitesRow, formattedResult: Pick<ReporterTestResult, 'testPath' | 'browserId' | 'attempt'>): void { | ||
const {testPath, browserId: browserName, attempt} = formattedResult; | ||
const {imagesInfo} = testResult; | ||
const {imagesInfo, ...resultWithoutImagesInfo} = testResult; | ||
const {browserVersion = BrowserVersions.UNKNOWN} = testResult.metaInfo as {browserVersion: string}; | ||
|
||
const suiteId = this._buildId(testPath); | ||
|
@@ -122,14 +122,16 @@ export class BaseTestsTreeBuilder { | |
|
||
this._addSuites(testPath, browserId); | ||
this._addBrowser({id: browserId, parentId: suiteId, name: browserName, version: browserVersion}, testResultId, attempt); | ||
this._addResult({id: testResultId, parentId: browserId, result: testResult}, imageIds); | ||
this._addResult({id: testResultId, parentId: browserId, result: resultWithoutImagesInfo}, imageIds); | ||
this._addImages(imageIds, {imagesInfo, parentId: testResultId}); | ||
|
||
this._setStatusForBranch(testPath); | ||
} | ||
|
||
protected _buildId(parentId: string | string[] = [], name: string | string[] = []): string { | ||
return ([] as string[]).concat(parentId, name).join(' '); | ||
const toStr = (value: string | string[]): string => Array.isArray(value) ? value.join(' ') : value; | ||
|
||
return name.length ? `${toStr(parentId)} ${toStr(name)}` : toStr(parentId); | ||
Comment on lines
-132
to
+134
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.
Такой вариант в два раза быстрее. Это не много, но Можно было и быстрее, но дальше код становится хуже 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. сколько мы здесь выигрываем по времени, что нужно трогать это место? |
||
} | ||
|
||
protected _addSuites(testPath: string[], browserId: string): void { | ||
|
@@ -200,13 +202,11 @@ export class BaseTestsTreeBuilder { | |
} | ||
|
||
protected _addResult({id, parentId, result}: ResultPayload, imageIds: string[]): void { | ||
const resultWithoutImagesInfo = _.omit(result, 'imagesInfo'); | ||
|
||
if (!this._tree.results.byId[id]) { | ||
this._tree.results.allIds.push(id); | ||
} | ||
|
||
this._tree.results.byId[id] = {id, parentId, ...resultWithoutImagesInfo, imageIds}; | ||
this._tree.results.byId[id] = {id, parentId, ...result, imageIds}; | ||
} | ||
|
||
protected _addImages(imageIds: string[], {imagesInfo, parentId}: ImagesPayload): void { | ||
|
@@ -225,18 +225,18 @@ export class BaseTestsTreeBuilder { | |
|
||
const suite = this._tree.suites.byId[suiteId]; | ||
|
||
const resultStatuses = _.compact(([] as (string | undefined)[]).concat(suite.browserIds)) | ||
const resultStatuses = (suite.browserIds || []) | ||
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. Тут и дальше по коду
|
||
.map((browserId: string) => { | ||
const browser = this._tree.browsers.byId[browserId]; | ||
const lastResultId = _.last(browser.resultIds) as string; | ||
|
||
return this._tree.results.byId[lastResultId].status; | ||
}); | ||
|
||
const childrenSuiteStatuses = _.compact(([] as (string | undefined)[]).concat(suite.suiteIds)) | ||
const childrenSuiteStatuses = (suite.suiteIds || []) | ||
.map((childSuiteId: string) => this._tree.suites.byId[childSuiteId].status); | ||
|
||
const status = determineStatus(_.compact([...resultStatuses, ...childrenSuiteStatuses])); | ||
const status = determineStatus([...resultStatuses, ...childrenSuiteStatuses].filter(Boolean) as TestStatus[]); | ||
|
||
// if newly determined status is the same as current status, do nothing | ||
if (suite.status === status) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,11 +59,11 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder { | |
const testId = this._buildId(testPath); | ||
const browserId = this._buildId(testId, browserName); | ||
|
||
attemptsMap.set(browserId, attemptsMap.has(browserId) ? attemptsMap.get(browserId) as number + 1 : 0); | ||
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. Тут мне не понравилась эта строчка, расписал понятнее |
||
const attempt = attemptsMap.get(browserId) as number; | ||
|
||
const testResult = mkTestResult(row, {attempt}); | ||
const formattedResult = {browserId: browserName, testPath, attempt}; | ||
const prevAttempts = attemptsMap.get(browserId); | ||
const curAttempts = prevAttempts === undefined ? 0 : prevAttempts + 1; | ||
attemptsMap.set(browserId, curAttempts); | ||
const testResult = mkTestResult(row, {attempt: curAttempts}); | ||
const formattedResult = {browserId: browserName, testPath, attempt: curAttempts}; | ||
|
||
addBrowserVersion(browsers, testResult); | ||
|
||
|
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.
Дальше по коду через
_.omit
вытаскиваютсяimagesInfo
изtestResult
Вместо того, чтобы передавать
testResult
полностью, сразу вытаскиваем ненужныйimagesInfo
без_.omit