-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix perf regressions #385
Fix perf regressions #385
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,12 @@ class FormAnalyzer { | |
shouldCheckUnifiedForm = false, | ||
shouldBeConservative = false | ||
}) { | ||
// If the string is empty or too long (noisy) do nothing | ||
if ( | ||
!string || | ||
string.length > constants.TEXT_LENGTH_CUTOFF | ||
) return this | ||
|
||
const matchesLogin = /current.?password/i.test(string) || this.matching.getDDGMatcherRegex('loginRegex')?.test(string) || this.matching.getDDGMatcherRegex('resetPasswordLink')?.test(string) | ||
|
||
// Check explicitly for unified login/signup forms | ||
|
@@ -177,9 +183,10 @@ class FormAnalyzer { | |
} | ||
|
||
evaluatePageHeadings () { | ||
const headings = document.querySelectorAll('h1, h2, h3, [class*="title"], [id*="title"]') | ||
headings.forEach(({textContent}) => { | ||
textContent = removeExcessWhitespace(textContent || '') | ||
const headings = document.querySelectorAll('h1, h2, h3') | ||
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. Removed |
||
headings.forEach((heading) => { | ||
const textContent = removeExcessWhitespace(heading.textContent || '') | ||
|
||
this.updateSignal({ | ||
string: textContent, | ||
strength: 0.5, | ||
|
@@ -256,10 +263,7 @@ class FormAnalyzer { | |
this.updateSignal({string, strength, signalType: `external link: ${string}`, shouldFlip}) | ||
} else { | ||
// any other case | ||
// only consider the el if it's a small text to avoid noisy disclaimers | ||
if (removeExcessWhitespace(el.textContent)?.length < constants.TEXT_LENGTH_CUTOFF) { | ||
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. The length check has been moved to |
||
this.updateSignal({string, strength: 1, signalType: `generic: ${string}`, shouldCheckUnifiedForm: true}) | ||
} | ||
this.updateSignal({string, strength: 1, signalType: `generic: ${string}`, shouldCheckUnifiedForm: true}) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,9 @@ class DefaultScanner { | |
return | ||
} | ||
|
||
// Do not add explicitly search forms | ||
if (parentForm.role === 'search') return | ||
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. Just occurred to me we shouldn't even add these obvious |
||
|
||
// Check if the forms we've seen are either disconnected, | ||
// or are parent/child of the currently-found form | ||
let previouslyFoundParent, childForm | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
This is the meat of the fix. We want to avoid running several regex checks on potentially huge chunks of text. This is what was causing the issues.