Skip to content
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

Remove dead code from FirebaseRemoteConfig #14153

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 0 additions & 8 deletions FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
/// Custom variable (aka App context digest). This is the pending custom variables request before
/// fetching.
@property(nonatomic, copy) NSDictionary *customVariables;
/// Cached internal metadata from internal metadata table. It contains customized information such
/// as HTTP connection timeout, HTTP read timeout, success/failure throttling rate and time
/// interval. Client has the default value of each parameters, they are only saved in
/// internalMetadata if they have been customize by developers.
@property(nonatomic, readonly, copy) NSDictionary *internalMetadata;
/// Device conditions since last successful fetch from the backend. Device conditions including
/// app
/// version, iOS version, device localte, language, GMP project ID and Game project ID. Used for
Expand Down Expand Up @@ -122,9 +117,6 @@
/// Returns metadata from metadata table.
- (NSDictionary *)loadConfigFromMetadataTable;

/// Updates internal content with the latest successful config response.
- (void)updateInternalContentWithResponse:(NSDictionary *)response;

/// Updates the metadata table with the current fetch status.
/// @param fetchSuccess True if fetch was successful.
- (void)updateMetadataWithFetchSuccessStatus:(BOOL)fetchSuccess
Expand Down
13 changes: 0 additions & 13 deletions FirebaseRemoteConfig/Sources/RCNConfigDBManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ typedef void (^RCNDBLoadCompletion)(BOOL success,
/// start. Config settings include success/failure fetch times, device contenxt, app context, etc.
- (NSDictionary *)loadMetadataWithBundleIdentifier:(NSString *)bundleIdentifier
namespace:(NSString *)namespace;
/// Load internal metadata from internal metadata table, such as customized HTTP connection/read
/// timeout, throttling time interval and number limit of throttling, etc.
/// This call needs to be blocking to ensure throttling works during apps starts.
- (NSDictionary *)loadInternalMetadataTable;
/// Load experiment from experiment table.
/// @param handler The callback when reading from DB is complete.
- (void)loadExperimentWithCompletionHandler:(RCNDBCompletion)handler;
Expand All @@ -90,10 +86,6 @@ typedef void (^RCNDBLoadCompletion)(BOOL success,
- (void)insertMainTableWithValues:(NSArray *)values
fromSource:(RCNDBSource)source
completionHandler:(RCNDBCompletion)handler;
/// Insert a record in internal metadata table.
/// @param values Values to be inserted.
- (void)insertInternalMetadataTableWithValues:(NSArray *)values
completionHandler:(RCNDBCompletion)handler;
/// Insert experiment data in experiment table.
/// @param key The key of experiment data belongs to, which are defined in
/// RCNConfigDefines.h.
Expand Down Expand Up @@ -125,11 +117,6 @@ typedef void (^RCNDBLoadCompletion)(BOOL success,
- (void)deleteRecordFromMainTableWithNamespace:(NSString *)namespace_p
bundleIdentifier:(NSString *)bundleIdentifier
fromSource:(RCNDBSource)source;
/// Remove all the records of given package name and namespace from metadata/internal metadata DB
/// before updating new values from response.
- (void)deleteRecordWithBundleIdentifier:(NSString *)bundlerIdentifier
namespace:(NSString *)namespace
isInternalDB:(BOOL)isInternalDB;
/// Remove all the records from a config content table.
- (void)deleteAllRecordsFromTableWithSource:(RCNDBSource)source;

Expand Down
95 changes: 0 additions & 95 deletions FirebaseRemoteConfig/Sources/RCNConfigDBManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#define RCNTableNameMainDefault "main_default"
#define RCNTableNameMetadataDeprecated "fetch_metadata"
#define RCNTableNameMetadata "fetch_metadata_v2"
#define RCNTableNameInternalMetadata "internal_metadata"
#define RCNTableNameExperiment "experiment"
#define RCNTableNamePersonalization "personalization"
#define RCNTableNameRollout "rollout"
Expand Down Expand Up @@ -278,10 +277,6 @@ - (BOOL)createTableSchema {
"success_fetch_time BLOB, failure_fetch_time BLOB, last_fetch_status INTEGER, "
"last_fetch_error INTEGER, last_apply_time INTEGER, last_set_defaults_time INTEGER)";

static const char *createTableInternalMetadata =
"create TABLE IF NOT EXISTS " RCNTableNameInternalMetadata
" (_id INTEGER PRIMARY KEY, key TEXT, value BLOB)";

static const char *createTableExperiment = "create TABLE IF NOT EXISTS " RCNTableNameExperiment
" (_id INTEGER PRIMARY KEY, key TEXT, value BLOB)";
static const char *createTablePersonalization =
Expand All @@ -293,7 +288,6 @@ - (BOOL)createTableSchema {

return [self executeQuery:createTableMain] && [self executeQuery:createTableMainActive] &&
[self executeQuery:createTableMainDefault] && [self executeQuery:createTableMetadata] &&
[self executeQuery:createTableInternalMetadata] &&
[self executeQuery:createTableExperiment] &&
[self executeQuery:createTablePersonalization] && [self executeQuery:createTableRollout];
}
Expand Down Expand Up @@ -471,48 +465,6 @@ - (BOOL)insertMainTableWithValues:(NSArray *)values fromSource:(RCNDBSource)sour
return YES;
}

- (void)insertInternalMetadataTableWithValues:(NSArray *)values
completionHandler:(RCNDBCompletion)handler {
__weak RCNConfigDBManager *weakSelf = self;
dispatch_async(_databaseOperationQueue, ^{
BOOL success = [weakSelf insertInternalMetadataWithValues:values];
if (handler) {
dispatch_async(dispatch_get_main_queue(), ^{
handler(success, nil);
});
}
});
}

- (BOOL)insertInternalMetadataWithValues:(NSArray *)values {
RCN_MUST_NOT_BE_MAIN_THREAD();
if (values.count != 2) {
return NO;
}
const char *SQL =
"INSERT OR REPLACE INTO " RCNTableNameInternalMetadata " (key, value) values (?, ?)";
sqlite3_stmt *statement = [self prepareSQL:SQL];
if (!statement) {
return NO;
}
NSString *aString = values[0];
if (![self bindStringToStatement:statement index:1 string:aString]) {
[self logErrorWithSQL:SQL finalizeStatement:statement returnValue:NO];
return NO;
}
NSData *blobData = values[1];
if (sqlite3_bind_blob(statement, 2, blobData.bytes, (int)blobData.length, NULL) != SQLITE_OK) {
[self logErrorWithSQL:SQL finalizeStatement:statement returnValue:NO];
return NO;
}
if (sqlite3_step(statement) != SQLITE_DONE) {
[self logErrorWithSQL:SQL finalizeStatement:statement returnValue:NO];
return NO;
}
sqlite3_finalize(statement);
return YES;
}

- (void)insertExperimentTableWithKey:(NSString *)key
value:(NSData *)serializedValue
completionHandler:(RCNDBCompletion)handler {
Expand Down Expand Up @@ -1039,34 +991,6 @@ - (NSData *)loadPersonalizationTableFromKey:(int)key {
return results[0];
}

- (NSDictionary *)loadInternalMetadataTable {
__block NSMutableDictionary *internalMetadataTableResult;
__weak RCNConfigDBManager *weakSelf = self;
dispatch_sync(_databaseOperationQueue, ^{
internalMetadataTableResult = [weakSelf loadInternalMetadataTableInternal];
});
return internalMetadataTableResult;
}

- (NSMutableDictionary *)loadInternalMetadataTableInternal {
NSMutableDictionary *internalMetadata = [[NSMutableDictionary alloc] init];
const char *SQL = "SELECT key, value FROM " RCNTableNameInternalMetadata;
sqlite3_stmt *statement = [self prepareSQL:SQL];
if (!statement) {
return nil;
}

while (sqlite3_step(statement) == SQLITE_ROW) {
NSString *key = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 0)];

NSData *dataValue = [NSData dataWithBytes:(char *)sqlite3_column_blob(statement, 1)
length:sqlite3_column_bytes(statement, 1)];
internalMetadata[key] = dataValue;
}
sqlite3_finalize(statement);
return internalMetadata;
}

/// This method is only meant to be called at init time. The underlying logic will need to be
/// reevaluated if the assumption changes at a later time.
- (void)loadMainWithBundleIdentifier:(NSString *)bundleIdentifier
Expand Down Expand Up @@ -1177,25 +1101,6 @@ - (void)deleteRecordFromMainTableWithNamespace:(NSString *)namespace_p
});
}

- (void)deleteRecordWithBundleIdentifier:(NSString *)bundleIdentifier
namespace:(NSString *)namespace
isInternalDB:(BOOL)isInternalDB {
__weak RCNConfigDBManager *weakSelf = self;
dispatch_async(_databaseOperationQueue, ^{
RCNConfigDBManager *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
const char *SQL = "DELETE FROM " RCNTableNameInternalMetadata " WHERE key LIKE ?";
NSArray *params = @[ bundleIdentifier ];
if (!isInternalDB) {
SQL = "DELETE FROM " RCNTableNameMetadata " WHERE bundle_identifier = ? and namespace = ?";
params = @[ bundleIdentifier, namespace ];
}
[strongSelf executeQuery:SQL withParams:params];
});
}

- (void)deleteAllRecordsFromTableWithSource:(RCNDBSource)source {
__weak RCNConfigDBManager *weakSelf = self;
dispatch_async(_databaseOperationQueue, ^{
Expand Down
45 changes: 0 additions & 45 deletions FirebaseRemoteConfig/Sources/RCNConfigSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ @interface RCNConfigSettings () {
/// Custom variables (aka App context digest). This is the pending custom variables request before
/// fetching.
NSMutableDictionary *_customVariables;
/// Cached internal metadata from internal metadata table. It contains customized information such
/// as HTTP connection timeout, HTTP read timeout, success/failure throttling rate and time
/// interval. Client has the default value of each parameters, they are only saved in
/// internalMetadata if they have been customize by developers.
NSMutableDictionary *_internalMetadata;
/// Last fetch status.
FIRRemoteConfigFetchStatus _lastFetchStatus;
/// Last fetch Error.
Expand All @@ -66,8 +61,6 @@ @interface RCNConfigSettings () {
NSString *_googleAppID;
/// The user defaults manager scoped to this RC instance of FIRApp and namespace.
RCNUserDefaultsManager *_userDefaultsManager;
/// The timestamp of last eTag update.
NSTimeInterval _lastETagUpdateTime;
}
@end

Expand All @@ -93,11 +86,6 @@ - (instancetype)initWithDatabaseManager:(RCNConfigDBManager *)manager
_successFetchTimes = [[NSMutableArray alloc] init];
_failureFetchTimes = [[NSMutableArray alloc] init];
_DBManager = manager;

_internalMetadata = [[_DBManager loadInternalMetadataTable] mutableCopy];
if (!_internalMetadata) {
_internalMetadata = [[NSMutableDictionary alloc] init];
}
_userDefaultsManager = [[RCNUserDefaultsManager alloc] initWithAppName:appName
bundleID:_bundleIdentifier
namespace:_FIRNamespace];
Expand Down Expand Up @@ -184,32 +172,6 @@ - (NSDictionary *)loadConfigFromMetadataTable {
}

#pragma mark - update DB/cached

// Update internal metadata content to cache and DB.
- (void)updateInternalContentWithResponse:(NSDictionary *)response {
// Remove all the keys with current package name.
[_DBManager deleteRecordWithBundleIdentifier:_bundleIdentifier
namespace:_FIRNamespace
isInternalDB:YES];

for (NSString *key in _internalMetadata.allKeys) {
if ([key hasPrefix:_bundleIdentifier]) {
[_internalMetadata removeObjectForKey:key];
}
}

for (NSString *entry in response) {
NSData *val = [response[entry] dataUsingEncoding:NSUTF8StringEncoding];
NSArray *values = @[ entry, val ];
_internalMetadata[entry] = response[entry];
[self updateInternalMetadataTableWithValues:values];
}
}

- (void)updateInternalMetadataTableWithValues:(NSArray *)values {
[_DBManager insertInternalMetadataTableWithValues:values completionHandler:nil];
}

/// If the last fetch was not successful, update the (exponential backoff) period that we wait until
/// fetching again. Any subsequent fetch requests will be checked and allowed only if past this
/// throttle end time.
Expand Down Expand Up @@ -310,9 +272,6 @@ - (void)updateFetchTimeWithSuccessFetch:(BOOL)isSuccessfulFetch {
}

- (void)updateMetadataTable {
[_DBManager deleteRecordWithBundleIdentifier:_bundleIdentifier
namespace:_FIRNamespace
isInternalDB:NO];
karenyz marked this conversation as resolved.
Show resolved Hide resolved
NSError *error;
// Objects to be serialized cannot be invalid.
if (!_bundleIdentifier) {
Expand Down Expand Up @@ -472,10 +431,6 @@ - (NSDictionary *)customVariables {
return [_customVariables copy];
}

- (NSDictionary *)internalMetadata {
return [_internalMetadata copy];
}

- (NSDictionary *)deviceContext {
return [_deviceContext copy];
}
Expand Down
33 changes: 0 additions & 33 deletions FirebaseRemoteConfig/Tests/Unit/RCNConfigDBManagerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,39 +155,6 @@ - (void)testWriteAndLoadMainTableResult {
}];
}

- (void)testWriteAndLoadInternalMetadataResult {
XCTestExpectation *loadConfigContentExpectation = [self
expectationWithDescription:@"Write and read internal metadata in database successfully"];
__block int count = 0;
for (int i = 0; i <= 100; ++i) {
// check DB write correctly
RCNDBCompletion insertCompletion = ^void(BOOL success, NSDictionary *result) {
count++;
XCTAssertTrue(success);
if (count == 100) {
// check DB read correctly
NSDictionary *result = [self->_DBManager loadInternalMetadataTable];
NSString *stringValue = [[NSString alloc] initWithData:result[@"key100"]
encoding:NSUTF8StringEncoding];
XCTAssertEqualObjects(stringValue, @"value100");
if (success) {
[loadConfigContentExpectation fulfill];
}
}
};
NSString *value = [NSString stringWithFormat:@"value%d", i];
NSString *key = [NSString stringWithFormat:@"key%d", i];

NSArray *values = @[ key, [value dataUsingEncoding:NSUTF8StringEncoding] ];
[_DBManager insertInternalMetadataTableWithValues:values completionHandler:insertCompletion];
}

[self waitForExpectationsWithTimeout:_expectionTimeout
handler:^(NSError *error) {
XCTAssertNil(error);
}];
}

- (void)testWriteAndLoadMetadataResult {
XCTestExpectation *writeAndLoadMetadataExpectation =
[self expectationWithDescription:@"Write and load metadata in database successfully"];
Expand Down
Loading
Loading