-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Refactor global init code and add more comments #33755
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
Changes from 5 commits
2e42865
adaf47e
9208f4f
05bf252
56ebeda
1223a77
73e0995
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,20 +1,20 @@ | ||
{{if .Flash.ErrorMsg}} | ||
{{- if .Flash.ErrorMsg -}} | ||
<div class="ui negative message flash-message flash-error"> | ||
<p>{{.Flash.ErrorMsg | SanitizeHTML}}</p> | ||
</div> | ||
{{end}} | ||
{{if .Flash.SuccessMsg}} | ||
{{- end -}} | ||
{{- if .Flash.SuccessMsg -}} | ||
<div class="ui positive message flash-message flash-success"> | ||
<p>{{.Flash.SuccessMsg | SanitizeHTML}}</p> | ||
</div> | ||
{{end}} | ||
{{if .Flash.InfoMsg}} | ||
{{- end -}} | ||
{{- if .Flash.InfoMsg -}} | ||
<div class="ui info message flash-message flash-info"> | ||
<p>{{.Flash.InfoMsg | SanitizeHTML}}</p> | ||
</div> | ||
{{end}} | ||
{{if .Flash.WarningMsg}} | ||
{{- end -}} | ||
{{- if .Flash.WarningMsg -}} | ||
<div class="ui warning message flash-message flash-warning"> | ||
<p>{{.Flash.WarningMsg | SanitizeHTML}}</p> | ||
</div> | ||
{{end}} | ||
{{- end -}} |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||||||||||||||
export class InitPerformanceTracer { | ||||||||||||||||||
results: {name: string, dur: number}[] = []; | ||||||||||||||||||
recordCall(name: string, func: ()=>void) { | ||||||||||||||||||
const start = performance.now(); | ||||||||||||||||||
func(); | ||||||||||||||||||
this.results.push({name, dur: performance.now() - start}); | ||||||||||||||||||
} | ||||||||||||||||||
printResults() { | ||||||||||||||||||
this.results = this.results.sort((a, b) => b.dur - a.dur); | ||||||||||||||||||
for (let i = 0; i < 20 && i < this.results.length; i++) { | ||||||||||||||||||
// eslint-disable-next-line no-console | ||||||||||||||||||
console.log(`performance trace: ${this.results[i].name} ${this.results[i].dur.toFixed(3)}`); | ||||||||||||||||||
} | ||||||||||||||||||
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.
Suggested change
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. I do not think it is performant, by the |
||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
export function callInitFunctions(functions: (() => any)[]): InitPerformanceTracer | null { | ||||||||||||||||||
// Start performance trace by accessing a URL by "https://localhost/?_ui_performance_trace=1" or "https://localhost/?key=value&_ui_performance_trace=1" | ||||||||||||||||||
// It is a quick check, no side effect so no need to do slow URL parsing. | ||||||||||||||||||
const perfTracer = !window.location.search.includes('_ui_performance_trace=1') ? null : new InitPerformanceTracer(); | ||||||||||||||||||
if (perfTracer) { | ||||||||||||||||||
for (const func of functions) perfTracer.recordCall(func.name, func); | ||||||||||||||||||
} else { | ||||||||||||||||||
for (const func of functions) func(); | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+20
to
+24
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.
Suggested change
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. I do not think it is performant. By using the |
||||||||||||||||||
return perfTracer; | ||||||||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.