Skip to content

Commit

Permalink
- move memory configuration from OCCoreManager to OCPlatform
Browse files Browse the repository at this point in the history
- effectively disable caching in minimum memory configuration for OCCore's thumbnail cache and OCResourceManager's OCResource cache
  • Loading branch information
felix-schwarz committed Nov 28, 2024
1 parent 1da7f56 commit a3c1563
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 56 deletions.
4 changes: 2 additions & 2 deletions ownCloudSDK/Bookmark/OCBookmark+DataItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import "OCDataTypes.h"
#import "OCResource.h"
#import "OCMacros.h"
#import "OCCoreManager.h"
#import "OCPlatform.h"

@implementation OCBookmark (DataItem)

Expand All @@ -36,7 +36,7 @@ - (OCDataItemReference)dataItemReference

- (OCDataItemVersion)dataItemVersion
{
if (OCCoreManager.sharedCoreManager.memoryConfiguration != OCCoreMemoryConfigurationMinimum)
if (OCPlatform.current.memoryConfiguration != OCPlatformMemoryConfigurationMinimum)
{
OCResource *avatarResource = OCTypedCast(self.avatar, OCResource);
NSString *avatarVersion = ((avatarResource != nil) ? avatarResource.version : @"");
Expand Down
6 changes: 3 additions & 3 deletions ownCloudSDK/Connection/OCConnection+Upload.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#import "OCHTTPResponse+DAVError.h"
#import "NSProgress+OCExtensions.h"
#import "OCCore+SyncEngine.h"
#import "OCCoreManager.h"
#import "OCPlatform.h"

typedef NSString* OCUploadInfoKey;
typedef NSString* OCUploadInfoTask;
Expand Down Expand Up @@ -241,7 +241,7 @@ - (OCProgress *)_tusUploadFileFromURL:(NSURL *)sourceURL withName:(NSString *)fi
{
NSNumber *capabilitiesTusMaxChunkSize;

if (OCCoreManager.sharedCoreManager.memoryConfiguration != OCCoreMemoryConfigurationMinimum)
if (OCPlatform.current.memoryConfiguration != OCPlatformMemoryConfigurationMinimum)
{
// Memory configuration is NOT minimum, so avoid splitting up files into chunks if
// possible, which requires additional memory and could mean going over a tight memory
Expand Down Expand Up @@ -296,7 +296,7 @@ - (OCProgress *)_continueTusJob:(OCTUSJob *)tusJob lastTask:(NSString *)lastTask
return (nil);
}

if (OCCoreManager.sharedCoreManager.memoryConfiguration == OCCoreMemoryConfigurationMinimum)
if (OCPlatform.current.memoryConfiguration == OCPlatformMemoryConfigurationMinimum)
{
// Memory configuration is minimum, so use just Creation instead of Creation-With-Upload
// to avoid splitting up files into chunks if possible, which requires additional memory
Expand Down
4 changes: 2 additions & 2 deletions ownCloudSDK/Core/ItemList/OCCore+ItemList.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ - (NSUInteger)parallelItemListTaskCount
{
switch (self.memoryConfiguration)
{
case OCCoreMemoryConfigurationMinimum:
case OCPlatformMemoryConfigurationMinimum:
return (1);
break;

case OCCoreMemoryConfigurationDefault:
case OCPlatformMemoryConfigurationDefault:
default:
return (2);
break;
Expand Down
11 changes: 3 additions & 8 deletions ownCloudSDK/Core/OCCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#import "OCDataSourceComposition.h"
#import "OCDataItemPresentable.h"
#import "OCShareRole.h"
#import "OCPlatform.h"

@class OCCore;
@class OCItem;
Expand Down Expand Up @@ -95,12 +96,6 @@ typedef NS_ENUM(NSUInteger, OCCoreConnectionStatusSignalState)
OCCoreConnectionStatusSignalStateForceTrue //!< Signal state is force true (overriding any false states)
} __attribute__((enum_extensibility(closed)));

typedef NS_ENUM(NSUInteger, OCCoreMemoryConfiguration)
{
OCCoreMemoryConfigurationDefault, //!< Default memory configuration
OCCoreMemoryConfigurationMinimum //!< Try using only the minimum amount of memory needed
} __attribute__((enum_extensibility(closed)));

typedef NS_ENUM(NSUInteger,OCCoreAvailableOfflineCoverage)
{
OCCoreAvailableOfflineCoverageNone, //!< Item is not targeted by available offline item policy
Expand Down Expand Up @@ -156,7 +151,7 @@ typedef id<NSObject> OCCoreItemTracking;
OCConnection *_connection;
BOOL _attemptConnect;

OCCoreMemoryConfiguration _memoryConfiguration;
OCPlatformMemoryConfiguration _memoryConfiguration;

NSMutableArray <OCQuery *> *_queries;

Expand Down Expand Up @@ -310,7 +305,7 @@ typedef id<NSObject> OCCoreItemTracking;
@property(readonly) OCVault *vault; //!< Vault managing storage and database access for this core.
@property(readonly) OCConnection *connection; //!< Connection used by the core to make requests to the server.

@property(assign,nonatomic) OCCoreMemoryConfiguration memoryConfiguration;
@property(assign,nonatomic) OCPlatformMemoryConfiguration memoryConfiguration;

@property(readonly,nonatomic) OCCoreState state;
@property(copy) OCCoreStateChangedHandler stateChangedHandler;
Expand Down
12 changes: 6 additions & 6 deletions ownCloudSDK/Core/OCCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ - (instancetype)initWithBookmark:(OCBookmark *)bookmark
[self addSignalProvider:_connectingStatusSignalProvider];
[self addSignalProvider:_connectionStatusSignalProvider];

self.memoryConfiguration = OCCoreManager.sharedCoreManager.memoryConfiguration;
self.memoryConfiguration = OCPlatform.current.memoryConfiguration;

[self startIPCObservation];
}
Expand Down Expand Up @@ -755,7 +755,7 @@ - (void)__attemptConnect
}

// If app provider is available and enabled
if (OCCoreManager.sharedCoreManager.memoryConfiguration != OCCoreMemoryConfigurationMinimum) // only load app providers in memory configurations other than minimum
if (self.memoryConfiguration != OCPlatformMemoryConfigurationMinimum) // only load app providers in memory configurations other than minimum
{
OCAppProvider *latestSupportedAppProvider = self.connection.capabilities.latestSupportedAppProvider;

Expand Down Expand Up @@ -1043,20 +1043,20 @@ - (OCMessageQueue *)messageQueue
}

#pragma mark - Memory configuration
- (void)setMemoryConfiguration:(OCCoreMemoryConfiguration)memoryConfiguration
- (void)setMemoryConfiguration:(OCPlatformMemoryConfiguration)memoryConfiguration
{
_memoryConfiguration = memoryConfiguration;

self.vault.resourceManager.memoryConfiguration = memoryConfiguration;

switch (_memoryConfiguration)
{
case OCCoreMemoryConfigurationDefault:
case OCPlatformMemoryConfigurationDefault:
_thumbnailCache.countLimit = OCCacheLimitNone;
break;

case OCCoreMemoryConfigurationMinimum:
_thumbnailCache.countLimit = 1;
case OCPlatformMemoryConfigurationMinimum:
_thumbnailCache.countLimit = 0;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ownCloudSDK/Core/Resources/Manager/OCResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef void(^OCResourceRetrieveCompletionHandler)(NSError * _Nullable error, OC
@property(weak,nullable) id<OCResourceStorage> storage;
@property(weak,nullable) OCCore *core;

@property(assign,nonatomic) OCCoreMemoryConfiguration memoryConfiguration;
@property(assign,nonatomic) OCPlatformMemoryConfiguration memoryConfiguration;

// @property(assign) NSUInteger maximumConcurrentJobs; //!< Maximum number of jobs to work on in parallel. A value of 0 indicates no limit.

Expand Down
8 changes: 4 additions & 4 deletions ownCloudSDK/Core/Resources/Manager/OCResourceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ - (instancetype)initWithStorage:(id<OCResourceStorage>)storage
return (self);
}

- (void)setMemoryConfiguration:(OCCoreMemoryConfiguration)memoryConfiguration
- (void)setMemoryConfiguration:(OCPlatformMemoryConfiguration)memoryConfiguration
{
_memoryConfiguration = memoryConfiguration;

switch (_memoryConfiguration)
{
case OCCoreMemoryConfigurationDefault:
case OCPlatformMemoryConfigurationDefault:
_cache.countLimit = OCCacheLimitNone;
break;

case OCCoreMemoryConfigurationMinimum:
_cache.countLimit = 1;
case OCPlatformMemoryConfigurationMinimum:
_cache.countLimit = 0;
break;
}
}
Expand Down
10 changes: 10 additions & 0 deletions ownCloudSDK/Platforms/OCPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@
#define OCView NSView
#endif /* TARGET_OS_OSX */

typedef NS_ENUM(NSUInteger, OCPlatformMemoryConfiguration)
{
OCPlatformMemoryConfigurationDefault, //!< Default memory configuration
OCPlatformMemoryConfigurationMinimum //!< Try using only the minimum amount of memory needed
} __attribute__((enum_extensibility(closed)));

NS_ASSUME_NONNULL_BEGIN

@interface OCPlatform : NSObject

@property(readonly,strong,nonatomic,class) OCPlatform *current;

@property(assign) OCPlatformMemoryConfiguration memoryConfiguration;

@end

NS_ASSUME_NONNULL_END
31 changes: 31 additions & 0 deletions ownCloudSDK/Platforms/OCPlatform.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,38 @@
*/

#import "OCPlatform.h"
#import "OCAppIdentity.h"
#import "OCSQLiteDB.h"

@implementation OCPlatform

+ (OCPlatform *)current
{
static OCPlatform *currentPlatform;

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
currentPlatform = [OCPlatform new];
});

return (currentPlatform);
}

- (instancetype)init
{
if ((self = [super init]) != nil)
{
_memoryConfiguration = OCPlatformMemoryConfigurationDefault;

if ([OCAppIdentity.sharedAppIdentity.componentIdentifier isEqual:OCAppComponentIdentifierFileProviderExtension] ||
[OCAppIdentity.sharedAppIdentity.componentIdentifier isEqual:OCAppComponentIdentifierFileProviderUIExtension] ||
[OCAppIdentity.sharedAppIdentity.componentIdentifier isEqual:OCAppComponentIdentifierShareExtension])
{
_memoryConfiguration = OCPlatformMemoryConfigurationMinimum;
}
}

return (self);
}

@end
1 change: 0 additions & 1 deletion ownCloudSDK/Resource Management/OCCoreManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ typedef void(^OCCoreManagerOfflineOperation)(OCBookmark *bookmark, dispatch_bloc
@property(class, readonly, strong, nonatomic) OCCoreManager *sharedCoreManager;

@property(assign) BOOL postFileProviderNotifications;
@property(assign,nonatomic) OCCoreMemoryConfiguration memoryConfiguration;

@property(readonly, nonatomic, strong) NSArray<OCCoreRunIdentifier> *activeRunIdentifiers;

Expand Down
23 changes: 0 additions & 23 deletions ownCloudSDK/Resource Management/OCCoreManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -411,29 +411,6 @@ - (void)_runNextOfflineOperationForBookmark:(OCBookmark *)bookmark
return (nil);
}

#pragma mark - Memory configuration
- (void)setMemoryConfiguration:(OCCoreMemoryConfiguration)memoryConfiguration
{
@synchronized (self)
{
_memoryConfiguration = memoryConfiguration;

[_coresByUUID enumerateKeysAndObjectsUsingBlock:^(NSUUID * _Nonnull key, OCCore * _Nonnull core, BOOL * _Nonnull stop) {
core.memoryConfiguration = memoryConfiguration;
}];

switch (memoryConfiguration)
{
case OCCoreMemoryConfigurationMinimum:
[OCSQLiteDB setMemoryLimit:(1 * 1024 * 512)]; // Set 0.5 MB memory limit for SQLite;
break;

default: break;
}

}
}

#pragma mark - Active run identifiers
- (NSArray<OCCoreRunIdentifier> *)activeRunIdentifiers
{
Expand Down
10 changes: 5 additions & 5 deletions ownCloudSDK/Vaults/Database/OCDatabase.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#import "OCAsyncSequentialQueue.h"
#import "NSString+OCSQLTools.h"
#import "OCItemPolicy.h"
#import "OCCoreManager.h"
#import "OCPlatform.h"
#import "NSArray+OCSegmentedProcessing.h"
#import "OCSQLiteDB+Internal.h"

Expand All @@ -50,7 +50,7 @@ @interface OCDatabase ()

OCAsyncSequentialQueue *_openQueue;
NSInteger _openCount;
OCCoreMemoryConfiguration _memoryConfiguration;
OCPlatformMemoryConfiguration _memoryConfiguration;

NSMutableSet<OCSyncRecordID> *_knownInvalidSyncRecordIDs;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ - (instancetype)initWithURL:(NSURL *)databaseURL

_selectItemRowsSQLQueryPrefix = @"SELECT mdID, mdTimestamp, syncAnchor, itemData";

_memoryConfiguration = OCCoreManager.sharedCoreManager.memoryConfiguration;
_memoryConfiguration = OCPlatform.current.memoryConfiguration;

_progressBySyncRecordID = [NSMutableDictionary new];
_ephermalParametersBySyncRecordID = [NSMutableDictionary new];
Expand Down Expand Up @@ -336,7 +336,7 @@ - (void)addCacheItems:(NSArray <OCItem *> *)items syncAnchor:(OCSyncAnchor)syncA
completionHandler(self, error);
}
}]];
} segmentSize:((_memoryConfiguration == OCCoreMemoryConfigurationMinimum) ? 10 : 200)];
} segmentSize:((_memoryConfiguration == OCPlatformMemoryConfigurationMinimum) ? 10 : 200)];
}

- (void)updateCacheItems:(NSArray <OCItem *> *)items syncAnchor:(OCSyncAnchor)syncAnchor completionHandler:(OCDatabaseCompletionHandler)completionHandler
Expand Down Expand Up @@ -452,7 +452,7 @@ - (void)updateCacheItems:(NSArray <OCItem *> *)items syncAnchor:(OCSyncAnchor)sy
completionHandler(self, error);
}
}]];
} segmentSize:((_memoryConfiguration == OCCoreMemoryConfigurationMinimum) ? 10 : 200)];
} segmentSize:((_memoryConfiguration == OCPlatformMemoryConfigurationMinimum) ? 10 : 200)];
}

- (void)removeCacheItems:(NSArray <OCItem *> *)items syncAnchor:(OCSyncAnchor)syncAnchor completionHandler:(OCDatabaseCompletionHandler)completionHandler
Expand Down
8 changes: 7 additions & 1 deletion ownCloudSDK/Vaults/Database/SQLite/OCSQLiteDB.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "NSProgress+OCExtensions.h"
#import "OCCoreManager.h"
#import "OCSQLiteCollationLocalized.h"
#import "OCPlatform.h"

#import "OCExtension+License.h"

Expand All @@ -49,6 +50,11 @@ @implementation OCSQLiteDB
+ (void)load
{
[[OCExtensionManager sharedExtensionManager] addExtension:[OCExtension licenseExtensionWithIdentifier:@"license.ISRunLoopThread" bundleOfClass:[OCRunLoopThread class] title:@"ISRunLoopThread" resourceName:@"ISRunLoopThread" fileExtension:@"LICENSE"]];

if (OCPlatform.current.memoryConfiguration == OCPlatformMemoryConfigurationMinimum)
{
[OCSQLiteDB setMemoryLimit:(1 * 1024 * 512)]; // Set 0.5 MB memory limit for SQLite;
}
}

+ (BOOL)allowConcurrentFileAccess
Expand All @@ -72,7 +78,7 @@ - (instancetype)init

_journalMode = OCSQLiteJournalModeDelete; // (SQLite default)

self.cacheStatements = (OCCoreManager.sharedCoreManager.memoryConfiguration != OCCoreMemoryConfigurationMinimum);
self.cacheStatements = (OCPlatform.current.memoryConfiguration != OCPlatformMemoryConfigurationMinimum);

#if TARGET_OS_IOS
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shrinkMemory) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
Expand Down

0 comments on commit a3c1563

Please sign in to comment.