@@ -1855,6 +1855,11 @@ - (void)_persistClusterDataAsNeeded
1855
1855
return;
1856
1856
}
1857
1857
1858
+ // Do not persist partial data in the middle of receiving a report. _handleReportEnd will schedule next persistence
1859
+ if (_receivingReport) {
1860
+ return;
1861
+ }
1862
+
1858
1863
NSDate * lastReportTime = [_mostRecentReportTimes lastObject];
1859
1864
NSTimeInterval intervalSinceLastReport = -[lastReportTime timeIntervalSinceNow];
1860
1865
if (intervalSinceLastReport < [self _reportToPersistenceDelayTimeAfterMutiplier]) {
@@ -2054,6 +2059,7 @@ - (void)_handleReportEnd
2054
2059
_receivingPrimingReport = NO;
2055
2060
_estimatedStartTimeFromGeneralDiagnosticsUpTime = nil;
2056
2061
2062
+ [self _commitPendingDataVersions];
2057
2063
[self _scheduleClusterDataPersistence];
2058
2064
2059
2065
// After the handling of the report, if we detected a device configuration change, notify the delegate
@@ -2519,6 +2525,30 @@ - (nullable MTRDeviceClusterData *)_clusterDataForPath:(MTRClusterPath *)cluster
2519
2525
return dataVersions;
2520
2526
}
2521
2527
2528
+ - (void)_commitPendingDataVersionsForClusterPath:(MTRClusterPath *)path
2529
+ {
2530
+ os_unfair_lock_assert_owner(&self->_lock);
2531
+ MTRDeviceClusterData * clusterData = _clusterDataToPersist[path];
2532
+ if (clusterData.pendingDataVersion) {
2533
+ clusterData.dataVersion = clusterData.pendingDataVersion;
2534
+ clusterData.pendingDataVersion = nil;
2535
+ }
2536
+ }
2537
+
2538
+ - (void)_commitPendingDataVersions
2539
+ {
2540
+ os_unfair_lock_assert_owner(&self->_lock);
2541
+
2542
+ if (!_clusterDataToPersist) {
2543
+ // nothing to do
2544
+ return;
2545
+ }
2546
+
2547
+ for (MTRClusterPath * path in _clusterDataToPersist) {
2548
+ [self _commitPendingDataVersionsForClusterPath:path];
2549
+ }
2550
+ }
2551
+
2522
2552
- (MTRDeviceDataValueDictionary _Nullable)_cachedAttributeValueForPath:(MTRAttributePath *)path
2523
2553
{
2524
2554
os_unfair_lock_assert_owner(&self->_lock);
@@ -3919,10 +3949,11 @@ - (void)_noteDataVersion:(NSNumber *)dataVersion forClusterPath:(MTRClusterPath
3919
3949
// Update data version used for subscription filtering
3920
3950
MTRDeviceClusterData * clusterData = [self _clusterDataForPath:clusterPath];
3921
3951
if (!clusterData) {
3922
- clusterData = [[MTRDeviceClusterData alloc] initWithDataVersion:dataVersion attributes:nil];
3952
+ clusterData = [[MTRDeviceClusterData alloc] init];
3953
+ clusterData.pendingDataVersion = dataVersion;
3923
3954
dataVersionChanged = YES;
3924
3955
} else if (![clusterData.dataVersion isEqualToNumber:dataVersion]) {
3925
- clusterData.dataVersion = dataVersion;
3956
+ clusterData.pendingDataVersion = dataVersion;
3926
3957
dataVersionChanged = YES;
3927
3958
}
3928
3959
0 commit comments