From 15b277fa8ec40c53712bdccad93fa8768e2648e2 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 31 Jan 2017 15:59:58 -0500 Subject: [PATCH] (fix) cache sogo_folder_info records and avoid phantom subscriptions (fixes #4010) --- SOPE/GDLContentStore/GCSFolderManager.h | 1 + SOPE/GDLContentStore/GCSFolderManager.m | 11 ++++++++--- SoObjects/SOGo/SOGoGCSFolder.m | 19 ++++++++++++++++++- SoObjects/SOGo/SOGoParentFolder.m | 8 +------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/SOPE/GDLContentStore/GCSFolderManager.h b/SOPE/GDLContentStore/GCSFolderManager.h index 8ec5ecf69..23927252d 100644 --- a/SOPE/GDLContentStore/GCSFolderManager.h +++ b/SOPE/GDLContentStore/GCSFolderManager.h @@ -77,6 +77,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; diff --git a/SOPE/GDLContentStore/GCSFolderManager.m b/SOPE/GDLContentStore/GCSFolderManager.m index 37c37231f..409254887 100644 --- a/SOPE/GDLContentStore/GCSFolderManager.m +++ b/SOPE/GDLContentStore/GCSFolderManager.m @@ -784,7 +784,7 @@ static BOOL _singleStoreMode = NO; return result; } -- (GCSFolder *) folderAtPath: (NSString *) _path +- (NSDictionary *) recordAtPath: (NSString *) _path { NSMutableString *sql; NSArray *fnames, *records; @@ -841,8 +841,13 @@ static BOOL _singleStoreMode = NO; [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 diff --git a/SoObjects/SOGo/SOGoGCSFolder.m b/SoObjects/SOGo/SOGoGCSFolder.m index 67520293a..c7ce63c84 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.m +++ b/SoObjects/SOGo/SOGoGCSFolder.m @@ -424,7 +424,23 @@ static NSArray *childRecordFields = nil; - (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 @@ -578,6 +594,7 @@ static NSArray *childRecordFields = nil; [self removeFolderSettings: moduleSettings withReference: [self folderReference]]; [us synchronize]; + [[SOGoCache sharedCache] removeValueForKey: ocsPath]; if ([[context request] handledByDefaultHandler]) [self sendFolderAdvisoryTemplate: @"Removal"]; diff --git a/SoObjects/SOGo/SOGoParentFolder.m b/SoObjects/SOGo/SOGoParentFolder.m index d3f3c4305..29f671813 100644 --- a/SoObjects/SOGo/SOGoParentFolder.m +++ b/SoObjects/SOGo/SOGoParentFolder.m @@ -291,14 +291,8 @@ static SoSecurityManager *sm = nil; // 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])