Skip to content

Commit

Permalink
Fix issue with long delays when changing enabled filter lists (#24330)…
Browse files Browse the repository at this point in the history
… (Uplift to 1.68.x) (#24538)

Fix issue with long delays when changing enabled filter lists (#24330)

* Fix issue with long delays when changing enabled filter lists

* Fix for review
  • Loading branch information
cuba authored Jul 8, 2024
1 parent 4be1636 commit 3aa7fd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,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 @@ -523,7 +527,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 @@ -536,7 +539,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 @@ -170,7 +170,7 @@ import WebKit
guard
let folderURL = FileManager.default.getOrCreateFolder(
name: "custom_rules",
location: .applicationDirectory
location: .applicationSupportDirectory
)
else {
throw ResourceFileError.failedToCreateCacheFolder
Expand Down Expand Up @@ -203,14 +203,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 3aa7fd0

Please sign in to comment.