Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios] Add cache management methods to the iosapp debug menu #15166

Draft
wants to merge 2 commits into
base: release-picklejuice
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion platform/darwin/test/MGLOfflineStorageTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,29 @@ - (void)testInvalidatePack {
[[MGLOfflineStorage sharedOfflineStorage] invalidatePack:pack withCompletionHandler:^(NSError * _Nullable) {
XCTAssertNotNil(pack);
XCTAssertNil(error);
[expectation fulfill];
}];
}];

// MGLCoordinateBounds columbus = MGLCoordinateBoundsMake(CLLocationCoordinate2DMake(39.916, -83.044), CLLocationCoordinate2DMake(40.004, -82.946));
//
// NSString *nameKey2 = @"Name";
// NSString *name2 = @"Paris square";
//
// NSData *context2 = [NSKeyedArchiver archivedDataWithRootObject:@{nameKey2: name2}];
// MGLTilePyramidOfflineRegion *region2 = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:styleURL bounds:columbus fromZoomLevel:10 toZoomLevel:11];
//
// [[MGLOfflineStorage sharedOfflineStorage] addPackForRegion:region2 withContext:context2 completionHandler:^(MGLOfflinePack * _Nullable pack, NSError * _Nullable error) {
// [[MGLOfflineStorage sharedOfflineStorage] removePack:pack withCompletionHandler:^(NSError * _Nullable error) {
// [[MGLOfflineStorage sharedOfflineStorage] invalidatePack:pack withCompletionHandler:^(NSError * _Nullable error) {
// XCTAssertNotNil(error);
// [expectation fulfill];
// }];
// }];
// }];

//


[self waitForExpectationsWithTimeout:10 handler:nil];
}

Expand Down Expand Up @@ -251,6 +271,8 @@ - (void)testClearCache {
XCTAssertNil(error);
[expectation fulfill];
}];


[self waitForExpectationsWithTimeout:10 handler:nil];
}

Expand All @@ -260,6 +282,26 @@ - (void)testResetDatabase {
XCTAssertNil(error);
[expectation fulfill];
}];

MGLCoordinateBounds bounds = {
{ .latitude = 48.8660, .longitude = 2.3306 },
{ .latitude = 48.8603, .longitude = 2.3213 },
};

NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];

// Attempting to reset the database while an offline pack is downloading should lead to an error.
MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:styleURL bounds:bounds fromZoomLevel:10 toZoomLevel:11];

NSString *nameKey = @"Name";
NSString *name = @"Paris square";

NSData *context = [NSKeyedArchiver archivedDataWithRootObject:@{nameKey: name}];
[[MGLOfflineStorage sharedOfflineStorage] addPackForRegion:region withContext:context completionHandler:nil];
[[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError * _Nullable error) {
XCTAssertNotNil(error);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:10 handler:nil];
}

Expand Down
75 changes: 72 additions & 3 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsDebugToolsRows) {
MBXSettingsDebugToolsOverdrawVisualization,
MBXSettingsDebugToolsShowZoomLevel,
MBXSettingsDebugToolsShowFrameTimeGraph,
MBXSettingsDebugToolsShowReuseQueueStats
MBXSettingsDebugToolsShowReuseQueueStats,
MBXSettingsDebugToolsInvalidateAmbientCache,
MBXSettingsDebugToolsClearAmbientCache,
MBXSettingsDebugToolsResetDatabase
};

typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) {
Expand Down Expand Up @@ -375,7 +378,10 @@ - (void)dismissSettings:(__unused id)sender
(debugMask & MGLMapDebugOverdrawVisualizationMask ? @"Hide" :@"Show")],
[NSString stringWithFormat:@"%@ zoom level ornament", (self.zoomLevelOrnamentEnabled ? @"Hide" :@"Show")],
[NSString stringWithFormat:@"%@ frame time graph", (self.frameTimeGraphEnabled ? @"Hide" :@"Show")],
[NSString stringWithFormat:@"%@ reuse queue stats", (self.reuseQueueStatsEnabled ? @"Hide" :@"Show")]
[NSString stringWithFormat:@"%@ reuse queue stats", (self.reuseQueueStatsEnabled ? @"Hide" :@"Show")],
@"Invalidate Ambient Cache",
@"Clear Ambient Cache",
@"Reset Database",
]];
break;
case MBXSettingsAnnotations:
Expand Down Expand Up @@ -508,11 +514,19 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
[self updateHUD];
break;
}
case MBXSettingsDebugToolsInvalidateAmbientCache:
[self invalidateAmbientCache];
break;
case MBXSettingsDebugToolsClearAmbientCache:
[self clearAmbientCache];
break;
case MBXSettingsDebugToolsResetDatabase:
[self resetDatabase];
break;
default:
NSAssert(NO, @"All debug tools setting rows should be implemented");
break;
}

self.mapView.debugMask = self.currentState.debugMask;

break;
Expand Down Expand Up @@ -1765,6 +1779,61 @@ - (NSString *)telemetryDebugLogFilePath
return filePath;
}

#pragma mark:
- (void)invalidateAmbientCache {
CFTimeInterval start = CACurrentMediaTime();
[[MGLOfflineStorage sharedOfflineStorage] invalidateAmbientCacheWithCompletionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
} else {
CFTimeInterval difference = CACurrentMediaTime() - start;
NSLog(@"Ambient cache invalidated in %f seconds", difference);
}
}];
}

- (void)invalidateOfflinePack {
CFTimeInterval start = CACurrentMediaTime();
MGLOfflinePack *pack = [MGLOfflineStorage sharedOfflineStorage].packs.firstObject;

[[MGLOfflineStorage sharedOfflineStorage] invalidatePack:pack withCompletionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
} else {
CFTimeInterval difference = CACurrentMediaTime() - start;
NSLog(@"Offline pack invalidated in %f seconds", difference);
}
}];
}

- (void)clearAmbientCache {
CFTimeInterval start = CACurrentMediaTime();
[[MGLOfflineStorage sharedOfflineStorage] clearAmbientCacheWithCompletionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
} else {
CFTimeInterval difference = CACurrentMediaTime() - start;
NSLog(@"Ambient cache cleared in %f seconds", difference);
}
}];
}

- (void)resetDatabase {
CFTimeInterval start = CACurrentMediaTime();
[[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
} else {
CFTimeInterval difference = CACurrentMediaTime() - start;
NSLog(@"Database reset in %f seconds", difference);
}
}];
}

#pragma mark - Random World Tour

- (void)addAnnotations:(NSInteger)numAnnotations aroundCoordinate:(CLLocationCoordinate2D)coordinate radius:(CLLocationDistance)radius {
Expand Down