Skip to content

Commit

Permalink
Refactor FXIOS-7301 - Remove 1 closure_body_length violation from Sea…
Browse files Browse the repository at this point in the history
…rchLoader.swift (#21335)
  • Loading branch information
ionixjunior committed Aug 27, 2024
1 parent 6eaddba commit a7d6276
Showing 1 changed file with 47 additions and 37 deletions.
84 changes: 47 additions & 37 deletions firefox-ios/Client/Frontend/Browser/SearchLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,49 +115,59 @@ class SearchLoader: Loader<Cursor<Site>, SearchViewModel>, FeatureFlaggable {
}

DispatchQueue.main.async {
let results = queries
defer {
GleanMetrics.Awesomebar.queryTime.stopAndAccumulate(timerid)
}
self.updateUIWithBookmarksAsSitesResults(queries: queries,
timerid: timerid,
historyHighlightsEnabled: historyHighlightsEnabled,
oldValue: oldValue)
}
}
}
}

let bookmarksSites = results[safe: 0] ?? []
var combinedSites = bookmarksSites
if !historyHighlightsEnabled {
let historySites = results[safe: 1] ?? []
combinedSites += historySites
}
private func updateUIWithBookmarksAsSitesResults(queries: [[Site]],
timerid: TimerId,
historyHighlightsEnabled: Bool,
oldValue: String) {
let results = queries
defer {
GleanMetrics.Awesomebar.queryTime.stopAndAccumulate(timerid)
}

let bookmarksSites = results[safe: 0] ?? []
var combinedSites = bookmarksSites
if !historyHighlightsEnabled {
let historySites = results[safe: 1] ?? []
combinedSites += historySites
}

// Load the data in the table view.
self.load(ArrayCursor(data: combinedSites))
// Load the data in the table view.
load(ArrayCursor(data: combinedSites))

// If the new search string is not longer than the previous
// we don't need to find an autocomplete suggestion.
guard oldValue.count < self.query.count else { return }
// If the new search string is not longer than the previous
// we don't need to find an autocomplete suggestion.
guard oldValue.count < query.count else { return }

// If we should skip the next autocomplete, reset
// the flag and bail out here.
guard !self.skipNextAutocomplete else {
self.skipNextAutocomplete = false
return
}
// If we should skip the next autocomplete, reset
// the flag and bail out here.
guard !skipNextAutocomplete else {
skipNextAutocomplete = false
return
}

// First, see if the query matches any URLs from the user's search history.
for site in combinedSites {
if let completion = self.completionForURL(site.url) {
self.autocompleteView.setAutocompleteSuggestion(completion)
return
}
}
// First, see if the query matches any URLs from the user's search history.
for site in combinedSites {
if let completion = completionForURL(site.url) {
autocompleteView.setAutocompleteSuggestion(completion)
return
}
}

// If there are no search history matches, try matching one of the Alexa top domains.
if let topDomains = self.topDomains {
for domain in topDomains {
if let completion = self.completionForDomain(domain) {
self.autocompleteView.setAutocompleteSuggestion(completion)
return
}
}
}
// If there are no search history matches, try matching one of the Alexa top domains.
if let topDomains = topDomains {
for domain in topDomains {
if let completion = completionForDomain(domain) {
autocompleteView.setAutocompleteSuggestion(completion)
return
}
}
}
Expand Down

0 comments on commit a7d6276

Please sign in to comment.