File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
WooCommerce/Classes/ViewRelated/Dashboard/TopPerformers Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ final class TopPerformersDashboardViewModel: ObservableObject {
8888 self . usageTracksEventEmitter = usageTracksEventEmitter
8989
9090 observeSyncingCompletion ( )
91+ observeProductChanges ( )
9192
9293 Task { @MainActor in
9394 self . timeRange = await loadLastTimeRange ( ) ?? . today
@@ -220,14 +221,7 @@ private extension TopPerformersDashboardViewModel {
220221 . store ( in: & subscriptions)
221222 }
222223
223- func observeProducts( ids: [ Int64 ] ) {
224- entityListeners = [ : ]
225- for id in ids {
226- if let listener = createProductEntityListener ( id: id) {
227- entityListeners [ id] = listener
228- }
229- }
230-
224+ func observeProductChanges( ) {
231225 hasProductChanges
232226 . debounce ( for: . milliseconds( 300 ) , scheduler: DispatchQueue . main)
233227 . sink { [ weak self] in
@@ -238,6 +232,15 @@ private extension TopPerformersDashboardViewModel {
238232 . store ( in: & subscriptions)
239233 }
240234
235+ func observeProducts( ids: [ Int64 ] ) {
236+ entityListeners = entityListeners. filter { ids. contains ( $0. key) }
237+ for id in ids {
238+ if entityListeners [ id] == nil , let listener = createProductEntityListener ( id: id) {
239+ entityListeners [ id] = listener
240+ }
241+ }
242+ }
243+
241244 func createProductEntityListener( id: Int64 ) -> EntityListener < Product > ? {
242245 guard var product = storageManager. viewStorage. loadProduct ( siteID: siteID, productID: id) ? . toReadOnly ( ) else {
243246 return nil
You can’t perform that action at this time.
0 commit comments