From 6b2612551712fe90559a8cbb75de6f391b0ec0d1 Mon Sep 17 00:00:00 2001 From: Jacob Sikorski Date: Mon, 23 Oct 2023 10:42:08 -0600 Subject: [PATCH] Make componentId non optional --- .../Browser/Helpers/LaunchHelper.swift | 3 +- .../FilterListResourceDownloader.swift | 2 +- .../Brave/WebFilters/FilterListStorage.swift | 3 +- .../ShieldStats/Adblock/AdBlockStats.swift | 1 - Sources/Data/models/FilterListSetting.swift | 4 +- .../Model.xcdatamodeld/.xccurrentversion | 2 +- .../Model26.xcdatamodel/contents | 235 ++++++++++++++++++ 7 files changed, 242 insertions(+), 8 deletions(-) create mode 100644 Sources/Data/models/Model.xcdatamodeld/Model26.xcdatamodel/contents diff --git a/Sources/Brave/Frontend/Browser/Helpers/LaunchHelper.swift b/Sources/Brave/Frontend/Browser/Helpers/LaunchHelper.swift index 1e9985d0600..a77fe353705 100644 --- a/Sources/Brave/Frontend/Browser/Helpers/LaunchHelper.swift +++ b/Sources/Brave/Frontend/Browser/Helpers/LaunchHelper.swift @@ -150,9 +150,8 @@ private extension FilterListStorage { if filterLists.isEmpty { // If we don't have filter lists yet loaded, use the settings return Set(allFilterListSettings.compactMap { setting in - guard let componentId = setting.componentId else { return nil } return .filterList( - componentId: componentId, + componentId: setting.componentId, isAlwaysAggressive: setting.isAlwaysAggressive ) }) diff --git a/Sources/Brave/WebFilters/FilterListResourceDownloader.swift b/Sources/Brave/WebFilters/FilterListResourceDownloader.swift index c579841264c..03b573e7fe7 100644 --- a/Sources/Brave/WebFilters/FilterListResourceDownloader.swift +++ b/Sources/Brave/WebFilters/FilterListResourceDownloader.swift @@ -79,7 +79,7 @@ public actor FilterListResourceDownloader { do { try await filterListSettings.asyncConcurrentForEach { setting in guard await setting.isEnabled == true else { return } - guard let componentId = await setting.componentId else { return } + let componentId = await setting.componentId guard FilterList.disabledComponentIDs.contains(componentId) else { return } // Try to load the filter list folder. We always have to compile this at start diff --git a/Sources/Brave/WebFilters/FilterListStorage.swift b/Sources/Brave/WebFilters/FilterListStorage.swift index 31023590c57..b260cc15feb 100644 --- a/Sources/Brave/WebFilters/FilterListStorage.swift +++ b/Sources/Brave/WebFilters/FilterListStorage.swift @@ -47,7 +47,8 @@ import Combine func loadFilterListSettings() { var componentIds: Set = [] allFilterListSettings = FilterListSetting.loadAllSettings(fromMemory: !persistChanges).filter({ setting in - guard let componentId = setting.componentId, !componentId.isEmpty, !componentIds.contains(componentId) else { + let componentId = setting.componentId + guard !componentId.isEmpty, !componentIds.contains(componentId) else { setting.delete(inMemory: persistChanges) return false } diff --git a/Sources/Brave/WebFilters/ShieldStats/Adblock/AdBlockStats.swift b/Sources/Brave/WebFilters/ShieldStats/Adblock/AdBlockStats.swift index 58c52f962e3..a99ee9592a6 100644 --- a/Sources/Brave/WebFilters/ShieldStats/Adblock/AdBlockStats.swift +++ b/Sources/Brave/WebFilters/ShieldStats/Adblock/AdBlockStats.swift @@ -291,7 +291,6 @@ public actor AdBlockStats { extension FilterListSetting { @MainActor var engineSource: CachedAdBlockEngine.Source? { - guard let componentId = componentId else { return nil } return .filterList(componentId: componentId) } } diff --git a/Sources/Data/models/FilterListSetting.swift b/Sources/Data/models/FilterListSetting.swift index c6de8459a2d..a0996740ce0 100644 --- a/Sources/Data/models/FilterListSetting.swift +++ b/Sources/Data/models/FilterListSetting.swift @@ -16,7 +16,7 @@ public final class FilterListSetting: NSManagedObject, CRUD { } @MainActor @NSManaged public var uuid: String - @MainActor @NSManaged public var componentId: String? + @MainActor @NSManaged public var componentId: String @MainActor @NSManaged public var isEnabled: Bool @MainActor @NSManaged public var isHidden: Bool @MainActor @NSManaged public var isAlwaysAggressive: Bool @@ -40,7 +40,7 @@ public final class FilterListSetting: NSManagedObject, CRUD { /// Create a filter list setting for the given UUID and enabled status @MainActor public class func create( - uuid: String, componentId: String?, isEnabled: Bool, isHidden: Bool, order: Int, inMemory: Bool, isAlwaysAggressive: Bool + uuid: String, componentId: String, isEnabled: Bool, isHidden: Bool, order: Int, inMemory: Bool, isAlwaysAggressive: Bool ) -> FilterListSetting { var newSetting: FilterListSetting! diff --git a/Sources/Data/models/Model.xcdatamodeld/.xccurrentversion b/Sources/Data/models/Model.xcdatamodeld/.xccurrentversion index bcbcdab8fd3..d81839d4a34 100644 --- a/Sources/Data/models/Model.xcdatamodeld/.xccurrentversion +++ b/Sources/Data/models/Model.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - Model25.xcdatamodel + Model26.xcdatamodel diff --git a/Sources/Data/models/Model.xcdatamodeld/Model26.xcdatamodel/contents b/Sources/Data/models/Model.xcdatamodeld/Model26.xcdatamodel/contents new file mode 100644 index 00000000000..6cf35111a4b --- /dev/null +++ b/Sources/Data/models/Model.xcdatamodeld/Model26.xcdatamodel/contents @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +