Skip to content

Commit

Permalink
Fix privacy config fetch in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Nov 28, 2023
1 parent af7bb15 commit 8e65a74
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 4 additions & 3 deletions DuckDuckGo/AppConfigurationFetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class AppConfigurationFetch {
}

func start(isBackgroundFetch: Bool = false,
isDebug: Bool = false,
completion: AppConfigurationFetchCompletion?) {
guard Self.shouldRefresh else {
// Statistics are not sent after a successful background refresh in order to reduce the time spent in the background, so they are checked
Expand All @@ -113,7 +114,7 @@ class AppConfigurationFetch {

type(of: self).fetchQueue.async {
let taskID = UIApplication.shared.beginBackgroundTask(withName: Constants.backgroundTaskName)
self.fetchConfigurationFiles(isBackground: isBackgroundFetch) { result in
self.fetchConfigurationFiles(isBackground: isBackgroundFetch, isDebug: isDebug) { result in
if !isBackgroundFetch {
type(of: self).fetchQueue.async {
self.sendStatistics {
Expand Down Expand Up @@ -165,10 +166,10 @@ class AppConfigurationFetch {
#endif
}

private func fetchConfigurationFiles(isBackground: Bool, onDidComplete: @escaping AppConfigurationFetchCompletion) {
private func fetchConfigurationFiles(isBackground: Bool, isDebug: Bool = false, onDidComplete: @escaping AppConfigurationFetchCompletion) {
Task {
self.markFetchStarted(isBackground: isBackground)
let result = await AppDependencyProvider.shared.configurationManager.update()
let result = await AppDependencyProvider.shared.configurationManager.update(isDebug: isDebug)

switch result {
case .noData:
Expand Down
12 changes: 6 additions & 6 deletions DuckDuckGo/Configuration/ConfigurationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ struct ConfigurationManager {
}
}

func update() async -> UpdateResult {
async let didFetchAnyTrackerBlockingDependencies = fetchAndUpdateTrackerBlockingDependencies()
func update(isDebug: Bool = false) async -> UpdateResult {
async let didFetchAnyTrackerBlockingDependencies = fetchAndUpdateTrackerBlockingDependencies(isDebug: isDebug)
async let didFetchExcludedDomains = fetchAndUpdateBloomFilterExcludedDomains()
async let didFetchBloomFilter = fetchAndUpdateBloomFilter()

Expand All @@ -80,21 +80,21 @@ struct ConfigurationManager {
}

@discardableResult
func fetchAndUpdateTrackerBlockingDependencies() async -> Bool {
let didFetchAnyTrackerBlockingDependencies = await fetchTrackerBlockingDependencies()
func fetchAndUpdateTrackerBlockingDependencies(isDebug: Bool = false) async -> Bool {
let didFetchAnyTrackerBlockingDependencies = await fetchTrackerBlockingDependencies(isDebug: isDebug)
if didFetchAnyTrackerBlockingDependencies {
updateTrackerBlockingDependencies()
}
return didFetchAnyTrackerBlockingDependencies
}

private func fetchTrackerBlockingDependencies() async -> Bool {
private func fetchTrackerBlockingDependencies(isDebug: Bool = false) async -> Bool {
var didFetchAnyTrackerBlockingDependencies = false

var tasks = [Configuration: Task<(), Swift.Error>]()
tasks[.trackerDataSet] = Task { try await fetcher.fetch(.trackerDataSet) }
tasks[.surrogates] = Task { try await fetcher.fetch(.surrogates) }
tasks[.privacyConfiguration] = Task { try await fetcher.fetch(.privacyConfiguration) }
tasks[.privacyConfiguration] = Task { try await fetcher.fetch(.privacyConfiguration, isDebug: isDebug) }

for (configuration, task) in tasks {
do {
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/ConfigurationDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ConfigurationDebugViewController: UITableViewController {
}

private func fetchAssets() {
AppConfigurationFetch().start { [weak tableView] result in
AppConfigurationFetch().start(isDebug: true) { [weak tableView] result in
switch result {
case .assetsUpdated(let protectionsUpdated):
if protectionsUpdated {
Expand Down

0 comments on commit 8e65a74

Please sign in to comment.