Skip to content

Commit

Permalink
soft revert history suggestions (#2711)
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy authored Apr 11, 2024
1 parent aad9ecc commit 2f1f4ea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Core/DefaultVariantManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extension FeatureName {
// Define your feature e.g.:
// public static let experimentalFeature = FeatureName(rawValue: "experimentalFeature")

// Experiment coming soon
public static let history = FeatureName(rawValue: "history")
public static let newSuggestionLogic = FeatureName(rawValue: "newSuggestionLogic")
}

public struct VariantIOS: Variant {
Expand Down Expand Up @@ -63,7 +63,7 @@ public struct VariantIOS: Variant {
VariantIOS(name: "sd", weight: doNotAllocate, isIncluded: When.always, features: []),
VariantIOS(name: "se", weight: doNotAllocate, isIncluded: When.always, features: []),

VariantIOS(name: "mc", weight: 1, isIncluded: When.inEnglish, features: []),
VariantIOS(name: "mc", weight: 1, isIncluded: When.inEnglish, features: [.newSuggestionLogic]),
VariantIOS(name: "md", weight: 1, isIncluded: When.inEnglish, features: [.history]),

returningUser
Expand Down
38 changes: 34 additions & 4 deletions DuckDuckGo/AutocompleteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import CoreData
import Persistence
import History
import Combine
import BrowserServicesKit

class AutocompleteViewController: UIViewController {

Expand Down Expand Up @@ -54,10 +55,16 @@ class AutocompleteViewController: UIViewController {
private var historyCoordinator: HistoryCoordinating!
private var bookmarksDatabase: CoreDataDatabase!
private var appSettings: AppSettings!
private var variantManager: VariantManager!

private lazy var cachedBookmarks: CachedBookmarks = {
CachedBookmarks(bookmarksDatabase)
}()

private lazy var cachedBookmarksSearch: BookmarksStringSearch = {
BookmarksCachingSearch(bookmarksStore: CoreDataBookmarksSearchStore(bookmarksStore: bookmarksDatabase))
}()

var backgroundColor: UIColor {
appSettings.currentAddressBarPosition.isBottom ?
UIColor(designSystemColor: .background) :
Expand All @@ -82,14 +89,16 @@ class AutocompleteViewController: UIViewController {

static func loadFromStoryboard(bookmarksDatabase: CoreDataDatabase,
historyCoordinator: HistoryCoordinating,
appSettings: AppSettings = AppDependencyProvider.shared.appSettings) -> AutocompleteViewController {
appSettings: AppSettings = AppDependencyProvider.shared.appSettings,
variantManager: VariantManager = DefaultVariantManager()) -> AutocompleteViewController {
let storyboard = UIStoryboard(name: "Autocomplete", bundle: nil)
guard let controller = storyboard.instantiateInitialViewController() as? AutocompleteViewController else {
fatalError("Failed to instatiate correct Autocomplete view controller")
}
controller.bookmarksDatabase = bookmarksDatabase
controller.historyCoordinator = historyCoordinator
controller.appSettings = appSettings
controller.variantManager = variantManager
return controller
}

Expand Down Expand Up @@ -178,6 +187,16 @@ class AutocompleteViewController: UIViewController {
selectedItem = -1
tableView.reloadData()

let bookmarks: [Suggestion]

if variantManager.inSuggestionExperiment {
bookmarks = [] // We'll supply bookmarks elsewhere
} else {
bookmarks = cachedBookmarksSearch.search(query: query).prefix(2).map {
.bookmark(title: $0.title, url: $0.url, isFavorite: $0.isFavorite, allowedInTopHits: true)
}
}

loader = SuggestionLoader(dataSource: self, urlFactory: { phrase in
guard let url = URL(trimmedAddressBarString: phrase),
let scheme = url.scheme,
Expand All @@ -195,7 +214,10 @@ class AutocompleteViewController: UIViewController {
self?.pendingRequest = false
}
guard error == nil else { return }
self?.updateSuggestions(result?.all ?? [])

let remoteResults = result?.all ?? []

self?.updateSuggestions(bookmarks + remoteResults)
}
}

Expand Down Expand Up @@ -333,11 +355,11 @@ extension AutocompleteViewController {
extension AutocompleteViewController: SuggestionLoadingDataSource {

func history(for suggestionLoading: Suggestions.SuggestionLoading) -> [HistorySuggestion] {
return historyCoordinator.history ?? []
return variantManager.inSuggestionExperiment ? (historyCoordinator.history ?? []) : []
}

func bookmarks(for suggestionLoading: Suggestions.SuggestionLoading) -> [Suggestions.Bookmark] {
return cachedBookmarks.all
return variantManager.inSuggestionExperiment ? cachedBookmarks.all : []
}

func suggestionLoading(_ suggestionLoading: Suggestions.SuggestionLoading, suggestionDataFromUrl url: URL, withParameters parameters: [String: String], completion: @escaping (Data?, Error?) -> Void) {
Expand All @@ -363,3 +385,11 @@ extension HistoryEntry: HistorySuggestion {
}

}

extension VariantManager {

var inSuggestionExperiment: Bool {
isSupported(feature: .newSuggestionLogic) || isSupported(feature: .history)
}

}

0 comments on commit 2f1f4ea

Please sign in to comment.