Skip to content

Commit

Permalink
(fix) cache sogo_folder_info records and avoid phantom subscriptions …
Browse files Browse the repository at this point in the history
…(fixes #4010)
  • Loading branch information
extrafu committed Jan 31, 2017
1 parent 9a1f91e commit 01983f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions SOPE/GDLContentStore/GCSFolderManager.h
Expand Up @@ -65,6 +65,7 @@
- (BOOL)folderExistsAtPath:(NSString *)_path;
- (NSArray *)listSubFoldersAtPath:(NSString *)_path recursive:(BOOL)_flag;

- (NSDictionary *) recordAtPath: (NSString *) _path;
- (GCSFolder *)folderAtPath:(NSString *)_path;

- (NSException *)createFolderOfType:(NSString *)_type withName:(NSString *)_name atPath:(NSString *)_path;
Expand Down
11 changes: 8 additions & 3 deletions SOPE/GDLContentStore/GCSFolderManager.m
Expand Up @@ -634,7 +634,7 @@ - (NSArray *)listSubFoldersAtPath:(NSString *)_path recursive:(BOOL)_recursive{
return result;
}

- (GCSFolder *) folderAtPath: (NSString *) _path
- (NSDictionary *) recordAtPath: (NSString *) _path
{
NSMutableString *sql;
NSArray *fnames, *records;
Expand Down Expand Up @@ -691,8 +691,13 @@ - (GCSFolder *) folderAtPath: (NSString *) _path
[self debugWithFormat:@"found no record for path: '%@'", _path];
return nil;
}

return [self folderForRecord:record];

return record;
}

- (GCSFolder *) folderAtPath: (NSString *) _path
{
return [self folderForRecord: [self recordAtPath: _path]];
}

- (NSString *) baseTableNameWithUID: (NSString *) _uid
Expand Down
19 changes: 18 additions & 1 deletion SoObjects/SOGo/SOGoGCSFolder.m
Expand Up @@ -439,7 +439,23 @@ - (GCSFolderManager *) folderManager

- (GCSFolder *) ocsFolderForPath: (NSString *) _path
{
return [[self folderManager] folderAtPath: _path];
NSDictionary *record;
SOGoCache *cache;

cache = [SOGoCache sharedCache];
record = [[cache valueForKey: _path] objectFromJSONString];

if (!record)
{
record = [[self folderManager] recordAtPath: _path];

if (!record)
return nil;

[cache setValue: [record jsonRepresentation] forKey: _path];
}

return [[self folderManager] folderForRecord: record];
}

- (BOOL) folderIsMandatory
Expand Down Expand Up @@ -590,6 +606,7 @@ - (NSException *) delete
[self removeFolderSettings: moduleSettings
withReference: [self folderReference]];
[us synchronize];
[[SOGoCache sharedCache] removeValueForKey: ocsPath];

if ([[context request] handledByDefaultHandler])
[self sendFolderAdvisoryTemplate: @"Removal"];
Expand Down
8 changes: 1 addition & 7 deletions SoObjects/SOGo/SOGoParentFolder.m
Expand Up @@ -297,14 +297,8 @@ - (BOOL) _appendSubscribedSource: (NSString *) sourceKey
// This is important because user A could delete folder X, and user B has subscribed to it.
// If the "default roles" are enabled for calendars/address books, -validatePersmission:.. will
// work (grabbing the default role) and the deleted resource will be incorrectly returned.
//
// FIXME - 2015/01/29 - this fix (24c6c8c91d421594bd51f07904d4cd3911cd187c) was reverted. Normally, we should add
// [subscribedFolder ocsFolderForPath: [subscribedFolder ocsPath]] to check the existence of the folder but it causes
// massive SQL traffic.
//
// The proper fix would be to check upon login and only upon login if GCS folders that we're subscribed to are still existent.
//
if (subscribedFolder
&& [subscribedFolder ocsFolderForPath: [subscribedFolder ocsPath]]
&& ![sm validatePermission: SOGoPerm_AccessObject
onObject: subscribedFolder
inContext: context])
Expand Down

0 comments on commit 01983f6

Please sign in to comment.