Skip to content

Commit

Permalink
fix: Optimize avatar cache expiration
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Feb 26, 2025
1 parent 3e08052 commit 151fc2a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
14 changes: 10 additions & 4 deletions NextcloudTalk/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#import <BackgroundTasks/BGTaskRequest.h>
#import <BackgroundTasks/BGTask.h>

#import <SDWebImage/SDImageCache.h>

#import "NCAudioController.h"
#import "NCAppBranding.h"
#import "NCDatabaseManager.h"
Expand Down Expand Up @@ -67,15 +69,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSLog(@"Configure App Settings");
[NCSettingsController sharedInstance];

// Perform logfile cleanup only once in app lifecycle
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[NCUtils removeOldLogfiles];
// Perform cleanup only once in app lifecycle
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void){
@autoreleasepool {
[NCUtils removeOldLogfiles];
[[SDImageCache sharedImageCache].diskCache removeExpiredData];
[[NCSettingsController sharedInstance] createAccountsFile];
}
});

UIDevice *currentDevice = [UIDevice currentDevice];
[NCUtils log:[NSString stringWithFormat:@"Starting %@, version %@, %@ %@, model %@", NSBundle.mainBundle.bundleIdentifier, [NCAppBranding getAppVersionString], currentDevice.systemName, currentDevice.systemVersion, currentDevice.model]];

//Init rooms manager to start receiving NSNotificationCenter notifications
// Init rooms manager to start receiving NSNotificationCenter notifications
[NCRoomsManager sharedInstance];

[self registerBackgroundFetchTask];
Expand Down
5 changes: 5 additions & 0 deletions NextcloudTalk/NCAPIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ - (void)initImageDownloaders
// Don't set the path to an app group in order to prevent crashes
[SDImageCache sharedImageCache].config.shouldDisableiCloud = YES;
[SDImageCache sharedImageCache].config.maxDiskSize = 100 * 1024 * 1024;
[SDImageCache sharedImageCache].config.maxDiskAge = 60 * 60 * 24 * 7 * 4; // 4 weeks

// We expire the cache once on app launch, see AppDelegate
[SDImageCache sharedImageCache].config.shouldRemoveExpiredDataWhenTerminate = NO;
[SDImageCache sharedImageCache].config.shouldRemoveExpiredDataWhenEnterBackground = NO;

NSString *userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (iOS) Nextcloud-Talk v%@",
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCSettingsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ typedef NS_ENUM(NSInteger, NCPreferredFileSorting) {
- (void)setContactSync:(BOOL)enabled;
- (BOOL)didReceiveCallsFromOldAccount;
- (void)setDidReceiveCallsFromOldAccount:(BOOL)receivedOldCalls;
- (void)createAccountsFile;

@end
7 changes: 0 additions & 7 deletions NextcloudTalk/NCSettingsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ - (id)init
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRevokedResponseReceived:) name:NCTokenRevokedResponseReceivedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(upgradeRequiredResponseReceived:) name:NCUpgradeRequiredResponseReceivedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(talkConfigurationHasChanged:) name:NCTalkConfigurationHashChangedNotification object:nil];

// No need to create the file immediately -> dispatch to background
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^(void){
@autoreleasepool {
[self createAccountsFile];
}
});
}
return self;
}
Expand Down

0 comments on commit 151fc2a

Please sign in to comment.