-
Notifications
You must be signed in to change notification settings - Fork 7
feat:Move New Resources to Important #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,9 @@ @interface AJPApplicationManager() { | |
| @property (nonatomic, strong) AJPFileUtil* fileUtil; | ||
| @property (nonatomic, strong) AJPRemoteFileUtil* remoteFileUtil; | ||
|
|
||
| // Helper method to check if a resource already exists in package important splits | ||
| - (BOOL)isResourceExistingInPackageImportantSplits:(AJPResource *)resource package:(AJPApplicationPackage *)package; | ||
|
|
||
| @end | ||
|
|
||
| @implementation AJPApplicationManager | ||
|
|
@@ -675,7 +678,8 @@ - (void)startDownload { | |
| self.resourceDownloadStatus = DOWNLOADING; | ||
| [self fetchReleaseConfigWithCompletionHandler:^(AJPApplicationManifest* manifest,NSError* error) { | ||
| if (error==nil && manifest != nil) { | ||
| self.downloadedApplicationManifest = manifest; | ||
| AJPApplicationManifest *transformedManifest = [self transformDownloadedManifest:manifest]; | ||
| self.downloadedApplicationManifest = transformedManifest ?: manifest; | ||
| self.releaseConfigDownloadStatus = COMPLETED; | ||
| [self cleanUpUnwantedFiles]; | ||
| [self updateConfig:manifest.config]; | ||
|
|
@@ -950,6 +954,75 @@ - (void)fetchReleaseConfigWithCompletionHandler:(AJPReleaseConfigCompletionHandl | |
| [manifestDataTask resume]; | ||
| } | ||
|
|
||
| - (BOOL)isResourceExistingInPackageImportantSplits:(AJPResource *)resource package:(AJPApplicationPackage *)package { | ||
| if (!resource || !package) { | ||
| return NO; | ||
| } | ||
|
|
||
| NSArray<AJPResource *> *allImportantSplits = [package allImportantSplits]; | ||
| for (AJPResource *existingResource in allImportantSplits) { | ||
| if ([existingResource.filePath isEqualToString:resource.filePath]) { | ||
| return YES; | ||
| } | ||
| } | ||
|
|
||
| return NO; | ||
| } | ||
|
|
||
| - (AJPApplicationManifest *)transformDownloadedManifest:(AJPApplicationManifest *)downloadedManifest { | ||
| if (!downloadedManifest) { | ||
| return nil; | ||
| } | ||
|
|
||
| AJPApplicationManifest *localManifest = [self getCurrentApplicationManifest]; | ||
|
|
||
| AJPApplicationPackage *transformedPackage = [[AJPApplicationPackage alloc] init]; | ||
| transformedPackage.version = downloadedManifest.package.version; | ||
| transformedPackage.name = downloadedManifest.package.name; | ||
| transformedPackage.important = [downloadedManifest.package.important mutableCopy]; | ||
| transformedPackage.lazy = [downloadedManifest.package.lazy mutableCopy]; | ||
|
|
||
| AJPApplicationResources *transformedResources = [[AJPApplicationResources alloc] init]; | ||
| transformedResources.resources = [downloadedManifest.resources.resources mutableCopy]; | ||
|
|
||
| NSDictionary<NSString*, AJPResource*> *localResources = localManifest.resources.resources; | ||
| NSMutableDictionary<NSString*, AJPResource*> *newResources = [transformedResources.resources mutableCopy]; | ||
|
|
||
| NSMutableArray<AJPResource*> *resourcesToMoveToImportant = [NSMutableArray array]; | ||
|
|
||
| for (NSString *resourceKey in newResources) { | ||
| AJPResource *newResource = newResources[resourceKey]; | ||
| AJPResource *localResource = localResources[resourceKey]; | ||
|
|
||
| // Check if resource is new or updated AND not already in local package important splits | ||
| if ((!localResource || ![newResource.url.absoluteString isEqualToString:localResource.url.absoluteString]) && | ||
| ![self isResourceExistingInPackageImportantSplits:newResource package:localManifest.package]) { | ||
| [resourcesToMoveToImportant addObject:newResource]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This resource will always go to package in all the subsequent runs. We should decide if a resource is new after checking for that resource in package also.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with android as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, added a check to see if we have it in pkg important as well before moving |
||
| } | ||
| } | ||
|
|
||
| if (resourcesToMoveToImportant.count > 0) { | ||
| NSMutableArray<AJPResource*> *updatedImportantSplits = [transformedPackage.important mutableCopy]; | ||
| [updatedImportantSplits addObjectsFromArray:resourcesToMoveToImportant]; | ||
| transformedPackage.important = updatedImportantSplits; | ||
|
|
||
| for (AJPResource *resource in resourcesToMoveToImportant) { | ||
| [newResources removeObjectForKey:resource.filePath]; | ||
| } | ||
| transformedResources.resources = newResources; | ||
|
|
||
| [self.tracker trackInfo:@"manifest_transformation" | ||
| value:[@{@"resources_moved_to_important": @(resourcesToMoveToImportant.count)} mutableCopy]]; | ||
| } | ||
|
|
||
| AJPApplicationManifest *transformedManifest = [[AJPApplicationManifest alloc] | ||
| initWithPackage:transformedPackage | ||
| config:downloadedManifest.config | ||
| resources:transformedResources]; | ||
|
|
||
| return transformedManifest; | ||
| } | ||
|
|
||
| # pragma mark - Config | ||
|
|
||
| - (AJPApplicationConfig *)readApplicationConfig { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuvrajjsingh0 Can you set index & properties as well in transformedPackage?