Skip to content

Commit e88a7a3

Browse files
committed
Make pluginResultsController lazy
1 parent f82b2c9 commit e88a7a3

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

WooCommerce/Classes/Authentication/Epilogue/SwitchStoreUseCase.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class SwitchStoreUseCase: SwitchStoreUseCaseProtocol {
1212

1313
private let stores: StoresManager
1414
private let storageManager: StorageManagerType
15-
private let ZendeskShared: ZendeskManagerProtocol = ZendeskProvider.shared
15+
private let zendeskShared: ZendeskManagerProtocol = ZendeskProvider.shared
1616

1717
private lazy var resultsController: ResultsController<StorageSite> = {
1818
return ResultsController(storageManager: storageManager, sortedBy: [])
@@ -73,9 +73,9 @@ final class SwitchStoreUseCase: SwitchStoreUseCaseProtocol {
7373
// https://github.com/woocommerce/woocommerce-ios/pull/2013#discussion_r454620804
7474
logOutOfCurrentStore {
7575
self.finalizeStoreSelection(storeID)
76-
// Inform ZD that the site has changed
76+
// Inform the Zendesk shared instance that the Store has been switched
7777
// https://github.com/woocommerce/woocommerce-ios/pull/8008/
78-
self.ZendeskShared.test_listenToSiteSwitchChanges()
78+
self.zendeskShared.observeStoreSwitch()
7979
onCompletion(true)
8080
}
8181
}

WooCommerce/Classes/Tools/Zendesk/ZendeskManager.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension NSNotification.Name {
2222
protocol ZendeskManagerProtocol: SupportManagerAdapter {
2323
typealias onUserInformationCompletion = (_ success: Bool, _ email: String?) -> Void
2424

25-
func test_listenToSiteSwitchChanges()
25+
func observeStoreSwitch()
2626

2727
/// Displays the Zendesk New Request view from the given controller, for users to submit new tickets.
2828
///
@@ -46,7 +46,7 @@ protocol ZendeskManagerProtocol: SupportManagerAdapter {
4646
}
4747

4848
struct NoZendeskManager: ZendeskManagerProtocol {
49-
func test_listenToSiteSwitchChanges() {
49+
func observeStoreSwitch() {
5050
// no-op
5151
}
5252

@@ -148,7 +148,9 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
148148

149149
/// Loads Plugins from the Storage Layer.
150150
///
151-
private var pluginResultsController: ResultsController<StorageSitePlugin> {
151+
private lazy var pluginResultsController: ResultsController<StorageSitePlugin> = updatePluginResultsController()
152+
153+
private func updatePluginResultsController() -> ResultsController<StorageSitePlugin> {
152154
var sitePredicate: NSPredicate? = nil
153155
if let siteID = stores.sessionManager.defaultSite?.siteID {
154156
sitePredicate = NSPredicate(format: "siteID == %lld", siteID)
@@ -163,12 +165,12 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
163165
sortedBy: pluginStatusDescriptor)
164166
}
165167

166-
func test_listenToSiteSwitchChanges() {
167-
print("Changed! SiteID: ")
168+
func observeStoreSwitch() {
169+
pluginResultsController = updatePluginResultsController()
168170
do {
169171
try pluginResultsController.performFetch()
170172
} catch {
171-
DDLogError(":(")
173+
DDLogError("ZendeskManager: Unable to update plugin results")
172174
}
173175
}
174176

@@ -249,6 +251,7 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
249251
///
250252
fileprivate override init() {
251253
super.init()
254+
try? pluginResultsController.performFetch()
252255
observeZendeskNotifications()
253256
}
254257

0 commit comments

Comments
 (0)