Skip to content

Commit

Permalink
Fix issue with long delays when changing enabled filter lists (brave#…
Browse files Browse the repository at this point in the history
…24330)

* Fix issue with long delays when changing enabled filter lists

* Fix for review
  • Loading branch information
cuba authored Jun 28, 2024
1 parent 8b1ea86 commit 36fab20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import os
await ContentBlockerManager.GenericBlocklistType.allCases.asyncConcurrentForEach {
genericType in
let blocklistType = ContentBlockerManager.BlocklistType.generic(genericType)
var missingModes = await self.contentBlockerManager.missingModes(
let missingModes = await self.contentBlockerManager.missingModes(
for: blocklistType,
version: genericType.version
)
Expand Down Expand Up @@ -302,7 +302,11 @@ import os
func compileEngineIfFilesAreReady(for engineType: GroupedAdBlockEngine.EngineType) {
let manager = self.getManager(for: engineType)
let enabledSources = sourceProvider.enabledSources(for: engineType)
guard manager.checkHasAllInfo(for: enabledSources) else { return }
let availableSources = manager.compilableFiles(for: enabledSources)
.map({ $0.filterListInfo.source })
guard enabledSources.allSatisfy({ availableSources.contains($0) }) else {
return
}

Task {
await manager.compileImmediatelyIfNeeded(
Expand Down Expand Up @@ -608,7 +612,6 @@ extension AdBlockEngineManager.FileInfo {
var enabledSources: [GroupedAdBlockEngine.Source] {
var enabledSources = FilterListStorage.shared.enabledSources
enabledSources.append(contentsOf: CustomFilterListStorage.shared.enabledSources)
enabledSources.append(contentsOf: [.filterListText])
return enabledSources
}

Expand All @@ -621,7 +624,6 @@ extension AdBlockEngineManager.FileInfo {
case .aggressive:
var sources = FilterListStorage.shared.sources(for: engineType)
sources.append(contentsOf: CustomFilterListStorage.shared.allSources)
sources.append(contentsOf: [.filterListText])
return sources
case .standard:
return FilterListStorage.shared.sources(for: engineType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ import WebKit
guard
let folderURL = FileManager.default.getOrCreateFolder(
name: "custom_rules",
location: .applicationDirectory
location: .applicationSupportDirectory
)
else {
throw ResourceFileError.failedToCreateCacheFolder
Expand Down Expand Up @@ -205,14 +205,20 @@ import WebKit
extension CustomFilterListStorage {
/// Gives us source representations of all the enabled custom filter lists
@MainActor var enabledSources: [GroupedAdBlockEngine.Source] {
return
var sources =
filterListsURLs
.filter(\.setting.isEnabled)
.map(\.setting.engineSource)
if (try? self.savedCustomRulesFileURL()) == nil { return sources }
sources.append(.filterListText)
return sources
}

/// Gives us source representations of all the custom filter lists
@MainActor var allSources: [GroupedAdBlockEngine.Source] {
return filterListsURLs.map(\.setting.engineSource)
var sources = filterListsURLs.map(\.setting.engineSource)
if (try? self.savedCustomRulesFileURL()) == nil { return sources }
sources.append(.filterListText)
return sources
}
}

0 comments on commit 36fab20

Please sign in to comment.