From 5cdb0414bbb20ed1d4a6c04c029f7c7e790c0b21 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 29 Jan 2021 10:18:20 -0500 Subject: [PATCH 1/2] optional modules --- .../MVMCoreLoadRequestOperation.m | 52 +++++++++++-------- .../LoadHandling/MVMCoreRequestParameters.h | 4 ++ .../LoadHandling/MVMCoreRequestParameters.m | 6 +++ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 966700a..29f35b3 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -191,29 +191,32 @@ // Never use the cache. completionHandler(nil,nil); - } else if (requestParameters.pageType.length != 0 && requestParameters.modules.count > 0) { + } else { + NSArray *modules = [requestParameters allModules]; + if (requestParameters.pageType.length != 0 && modules.count > 0) { - // Check cache function for page json is already in the cache. - [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { + // Check cache function for page json is already in the cache. + [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - // Check cache function for modules already in the cache. - NSDictionary *pageDictionary = jsonDictionary; - [[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - completionHandler(pageDictionary,jsonDictionary); + // Check cache function for modules already in the cache. + NSDictionary *pageDictionary = jsonDictionary; + [[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) { + completionHandler(pageDictionary,jsonDictionary); + }]; }]; - }]; - } else if (requestParameters.pageType.length != 0) { + } else if (requestParameters.pageType.length != 0) { - // Check cache function if page json is already in the cache. - [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - completionHandler(jsonDictionary,nil); - }]; - } else if (requestParameters.modules.count > 0) { - - // Check cache function if modules already in the cache. - [[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - completionHandler(nil,jsonDictionary); - }]; + // Check cache function if page json is already in the cache. + [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { + completionHandler(jsonDictionary,nil); + }]; + } else if (modules > 0) { + + // Check cache function if modules already in the cache. + [[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) { + completionHandler(nil,jsonDictionary); + }]; + } } } @@ -239,16 +242,21 @@ // Check if the page was found in the cache. BOOL pageNotInCache = loadObject.operation.requestParameters.pageType && !loadObject.pageDataFromCache; - // Check all modules were found in the cache + // Check all required modules were found in the cache NSMutableArray *modulesNotInCache = [NSMutableArray array]; - for (NSString *module in loadObject.operation.requestParameters.modules) { + NSMutableArray *requiredModules = [NSMutableArray arrayWithArray:loadObject.operation.requestParameters.modules]; + for (NSString *module in [loadObject.operation.requestParameters allModules]) { if (![loadObject.modulesJSON objectForKey:module]) { + // Missing a module. [modulesNotInCache addObject:module]; + } else { + // Received a required module. + [requiredModules removeObject:module]; } } MVMCoreRequestParameters *requestParametersForServer = nil; - if (pageNotInCache || modulesNotInCache.count > 0) { + if (pageNotInCache || requiredModules.count > 0) { // We are missing data, will need to go to server. requestParametersForServer = [loadObject.operation.requestParameters copy]; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h index df2aa69..7dbe729 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h @@ -29,6 +29,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { // request parameters @property (nullable, strong, nonatomic) NSString *pageType; +@property (nullable, strong, nonatomic) NSArray *optionalModules; @property (nullable, strong, nonatomic) NSArray *modules; @property (nullable, strong, nonatomic) NSDictionary *parameters; @property (nullable, strong, nonatomic) NSData *imageData; @@ -120,4 +121,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { // Sets the load style based on the server sent presentationStyle - (void)setMFLoadStyleBasedOnPresentationStyle:(nonnull NSString *)presentationStyle; +/// Returns optional and required modules +- (nullable NSArray *)allModules; + @end diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index 5279dcc..b8e5877 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -116,6 +116,12 @@ } } +- (nullable NSArray *)allModules { + NSMutableSet *set = [NSMutableSet setWithArray:self.optionalModules]; + [set addObjectsFromArray:self.modules]; + return [set allObjects]; +} + - (id)copyWithZone:(nullable NSZone *)zone { MVMCoreRequestParameters *copyObject = [[MVMCoreRequestParameters alloc] init]; From 9a1dd39dffbac9a6ee3f7a214fe4a39a71a397fe Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 4 Feb 2021 17:09:53 -0500 Subject: [PATCH 2/2] optional modules --- MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h | 6 +++--- MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h index 7dbe729..2e52a05 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h @@ -29,8 +29,8 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { // request parameters @property (nullable, strong, nonatomic) NSString *pageType; -@property (nullable, strong, nonatomic) NSArray *optionalModules; -@property (nullable, strong, nonatomic) NSArray *modules; +@property (nullable, strong, nonatomic) NSArray *optionalModules; +@property (nullable, strong, nonatomic) NSArray *modules; @property (nullable, strong, nonatomic) NSDictionary *parameters; @property (nullable, strong, nonatomic) NSData *imageData; @@ -122,6 +122,6 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { - (void)setMFLoadStyleBasedOnPresentationStyle:(nonnull NSString *)presentationStyle; /// Returns optional and required modules -- (nullable NSArray *)allModules; +- (nullable NSArray *)allModules; @end diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index 3ba9319..c4327e1 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -33,7 +33,8 @@ - (nullable instancetype)initWithPageType:(nonnull NSString *)pageType extraParameters:(nullable NSDictionary *)extraParameters { if (self = [self initWithExtraParameters:extraParameters]) { self.pageType = pageType; - self.modules = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] allModulesForPageType:pageType]; + self.optionalModules = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] modulesOptionalForPageType:pageType]; + self.modules = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] modulesRequiredForPageType:pageType]; } return self; } @@ -127,7 +128,7 @@ MVMCoreRequestParameters *copyObject = [[MVMCoreRequestParameters alloc] init]; copyObject.pageType = [self.pageType copy]; copyObject.parentPageType = self.parentPageType; - + copyObject.optionalModules = [self.optionalModules copy]; copyObject.modules = [self.modules copy]; copyObject.parameters = [self.parameters copy]; copyObject.contextRoot = [self.contextRoot copy];