Skip to content

Commit

Permalink
- support for custom poll interval for changes:
Browse files Browse the repository at this point in the history
	- through capabilities: mirroring changes from owncloud/client#8777
	- through MDM via `core.scan-for-changes-interval`
	- in milliseconds
	- defaulting to 10 seconds
	- enforcing (and logging a warning) for intervals below a minimum of 5 seconds
	- logging a warning for intervals greater than 60 seconds
  • Loading branch information
felix-schwarz committed Aug 22, 2021
1 parent ad566e8 commit 19166c3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
57 changes: 38 additions & 19 deletions ownCloudSDK/Core/ItemList/OCCore+ItemList.m
Original file line number Diff line number Diff line change
Expand Up @@ -1197,10 +1197,10 @@ - (void)queueRequestJob:(OCAsyncSequentialQueueJob)requestJob
- (void)startCheckingForUpdates
{
[self queueBlock:^{
if (_directoryUpdateStartTime == 0)
if (self->_directoryUpdateStartTime == 0)
{
OCTLog(@[@"UpdateScan"], @"Starting update scan");
_directoryUpdateStartTime = NSDate.timeIntervalSinceReferenceDate;
self->_directoryUpdateStartTime = NSDate.timeIntervalSinceReferenceDate;
}

[self _checkForUpdatesNotBefore:nil inBackground:NO completionHandler:nil];
Expand Down Expand Up @@ -1445,35 +1445,54 @@ - (void)_handleRetrieveItemListEvent:(OCEvent *)event sender:(id)sender
if ((event.depth == 0) && ([event.path isEqual:@"/"]))
{
// Check again after configured time interval (with fall back to 10 seconds)
NSTimeInterval minimumTimeInterval = 10.0;

// Ignore until https://github.com/owncloud/client/pull/8777/files is resolved:
const NSTimeInterval defaultMinimumPollInterval = 10.0, minimumAllowedPollInterval = 5.0;
NSTimeInterval effectivePollInterval = defaultMinimumPollInterval;

// Server default is 60 seconds, but iOS default is 10 seconds
// also the capability is no longer in seconds, but milliseconds,
// so ignore anything less than 5 seconds
// so ignore anything less than 5 seconds, warn for anything greater
// than 60 seconds

// if ((self.connection.capabilities.pollInterval != nil) && (self.connection.capabilities.pollInterval.integerValue > 4999))
// {
// minimumTimeInterval = self.connection.capabilities.pollInterval.doubleValue / 1000.0;
// }
//
// NSNumber *configuredInterval;
//
// if ((configuredInterval = [self classSettingForOCClassSettingsKey:OCCoreScanForChangesInterval]) != nil)
// {
// minimumTimeInterval = configuredInterval.doubleValue / 1000.0;
// }
if ((self.connection.capabilities.pollInterval != nil) && (self.connection.capabilities.pollInterval.doubleValue > (minimumAllowedPollInterval * 1000.0)))
{
effectivePollInterval = self.connection.capabilities.pollInterval.doubleValue / 1000.0;

if (effectivePollInterval > 60.0)
{
OCLogWarning(@"Capabilities: poll interval %f > 60 seconds", effectivePollInterval);
}
}
else if (self.connection.capabilities.pollInterval.integerValue != 60)
{
OCLog(@"Poll interval in capabilities (%@) not server legacy default (60), but also less than minimum allowed poll interval (%f milliseconds), using default interval (%f milliseconds)", self.connection.capabilities.pollInterval, minimumAllowedPollInterval, defaultMinimumPollInterval);
}

NSNumber *configuredInterval;

if ((configuredInterval = [self classSettingForOCClassSettingsKey:OCCoreScanForChangesInterval]) != nil)
{
effectivePollInterval = configuredInterval.doubleValue / 1000.0;

if (effectivePollInterval > 60.0)
{
OCLogWarning(@"MDM/Branding: poll interval %f > 60 seconds", effectivePollInterval);
}
else if (effectivePollInterval < 5.0)
{
OCLogWarning(@"MDM/Branding: poll interval %f < 5 seconds - using default interval (%f)", effectivePollInterval, defaultMinimumPollInterval);
effectivePollInterval = defaultMinimumPollInterval;
}
}

if (self.state == OCCoreStateRunning)
{
@synchronized([OCCoreItemList class])
{
if ((_lastScheduledItemListUpdateDate==nil) || ([_lastScheduledItemListUpdateDate timeIntervalSinceNow]<-(minimumTimeInterval-1)))
if ((_lastScheduledItemListUpdateDate==nil) || ([_lastScheduledItemListUpdateDate timeIntervalSinceNow]<-(effectivePollInterval-1)))
{
_lastScheduledItemListUpdateDate = [NSDate date];

[self _checkForUpdatesNotBefore:[NSDate dateWithTimeIntervalSinceNow:minimumTimeInterval] inBackground:NO completionHandler:nil];
[self _checkForUpdatesNotBefore:[NSDate dateWithTimeIntervalSinceNow:effectivePollInterval] inBackground:NO completionHandler:nil];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ownCloudSDK/Core/OCCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ + (OCClassSettingsMetadataCollection)classSettingsMetadata

OCCoreScanForChangesInterval : @{
OCClassSettingsMetadataKeyType : OCClassSettingsMetadataTypeInteger,
OCClassSettingsMetadataKeyDescription : @"Minimum number of milliseconds until the next scan for changes, measured from the completion of the previous scan. If no value is provided, uses the pollinterval provided in the server's capabilities. If none is provided either, defaults to 10 seconds.",
OCClassSettingsMetadataKeyDescription : @"Minimum number of milliseconds until the next scan for changes, measured from the completion of the previous scan. If no value is provided, uses the poll interval provided in the server's capabilities (in milliseconds) if it is greater or equal 5 seconds. Defaults to 10 seconds otherwise.",
OCClassSettingsMetadataKeyStatus : OCClassSettingsKeyStatusAdvanced,
OCClassSettingsMetadataKeyCategory : @"Connection",
},
Expand Down

0 comments on commit 19166c3

Please sign in to comment.