Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ public class PlacesReadConnection {
}
}

open func getMostRecentHistoryMetadata(limit: Int32) throws -> [HistoryMetadata] {
return try queue.sync {
try self.checkApi()
return try self.conn.getMostRecentHistoryMetadata(limit: limit)
}
}

open func queryHistoryMetadata(query: String, limit: Int32) throws -> [HistoryMetadata] {
return try queue.sync {
try self.checkApi()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ final class DefaultRecentSearchProvider: RecentSearchProvider {
private let logger: Logger
private let nimbus: FxNimbus

private var maxNumberOfSuggestions: Int {
return nimbus.features.recentSearchesFeature.value().maxSuggestions
private var maxNumberOfSuggestions: Int32 {
return Int32(nimbus.features.recentSearchesFeature.value().maxSuggestions)
}

init(
Expand Down Expand Up @@ -57,16 +57,14 @@ final class DefaultRecentSearchProvider: RecentSearchProvider {
/// Only care about returning the `maxNumberOfSuggestions`.
/// We don't have an interface to fetch only a certain amount, so we follow what Android does for now.
func loadRecentSearches(completion: @escaping ([String]) -> Void) {
// TODO: FXIOS-13782 Use get_most_recent method to fetch history
historyStorage.getHistoryMetadataSince(since: Int64.min) { [weak self] result in
if case .success(let historyMetadata) = result {
let uniqueSearchTermResult = historyMetadata.compactMap { $0.searchTerm }
.uniqued()
.prefix(self?.maxNumberOfSuggestions ?? 5)
completion(Array(uniqueSearchTermResult))
} else {
completion([])
}
}
historyStorage.getMostRecentHistoryMetadata(limit: maxNumberOfSuggestions) { result in
if case .success(let historyMetadata) = result {
let uniqueSearchTermResult = historyMetadata.compactMap { $0.searchTerm }
.uniqued()
completion(uniqueSearchTermResult)
} else {
completion([])
}
}
}
}
11 changes: 6 additions & 5 deletions firefox-ios/Storage/Rust/RustPlaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public protocol BookmarksHandler {
public protocol HistoryHandler {
func applyObservation(visitObservation: VisitObservation,
completion: @escaping (Result<Void, any Error>) -> Void)
func getHistoryMetadataSince(
since startDate: Int64,

func getMostRecentHistoryMetadata(
limit: Int32,
completion: @Sendable @escaping (Result<[HistoryMetadata], any Error>) -> Void
)

Expand Down Expand Up @@ -550,12 +551,12 @@ public class RustPlaces: @unchecked Sendable, BookmarksHandler, HistoryHandler {

// MARK: History metadata
/// Currently only used to get the recent searches from the user's history storage.
public func getHistoryMetadataSince(
since startDate: Int64,
public func getMostRecentHistoryMetadata(
limit: Int32,
completion: @Sendable @escaping (Result<[HistoryMetadata], any Error>) -> Void
) {
withReader({ connection in
return try connection.getHistoryMetadataSince(since: startDate)
return try connection.getMostRecentHistoryMetadata(limit: limit)
}, completion: completion)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class MockHistoryHandler: HistoryHandler {
var onApply: (() -> Void)?

// MARK: History Metadata
var getHistoryMetadataSinceCallCount = 0
var getMostRecentHistoryMetadataCallCount = 0
var noteHistoryMetadataCallCount = 0
var result: Result<[MozillaAppServices.HistoryMetadata], Error> = .success(
[
Expand Down Expand Up @@ -53,11 +53,11 @@ final class MockHistoryHandler: HistoryHandler {
onApply?()
}

func getHistoryMetadataSince(
since startDate: Int64,
func getMostRecentHistoryMetadata(
limit: Int32,
completion: @escaping @Sendable (Result<[MozillaAppServices.HistoryMetadata], any Error>) -> Void
) {
getHistoryMetadataSinceCallCount += 1
getMostRecentHistoryMetadataCallCount += 1
completion(result)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ final class DefaultRecentSearchProviderTests: XCTestCase {
expectation.fulfill()
}
wait(for: [expectation], timeout: 1)
XCTAssertEqual(mockHistoryStorage.getMostRecentHistoryMetadataCallCount, 1)
}

func test_loadRecentSearches_withError_returnsEmptyList() {
Expand All @@ -75,6 +76,7 @@ final class DefaultRecentSearchProviderTests: XCTestCase {
expectation.fulfill()
}
wait(for: [expectation], timeout: 1)
XCTAssertEqual(mockHistoryStorage.getMostRecentHistoryMetadataCallCount, 1)
}

func createSubject(for searchEngineID: String) -> RecentSearchProvider {
Expand Down