Skip to content

Commit 7cfb06f

Browse files
authored
Remove dead code from FirebaseRemoteConfig (#14153)
1 parent cb0bc77 commit 7cfb06f

File tree

6 files changed

+7
-346
lines changed

6 files changed

+7
-346
lines changed

FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@
5555
/// Custom variable (aka App context digest). This is the pending custom variables request before
5656
/// fetching.
5757
@property(nonatomic, copy) NSDictionary *customVariables;
58-
/// Cached internal metadata from internal metadata table. It contains customized information such
59-
/// as HTTP connection timeout, HTTP read timeout, success/failure throttling rate and time
60-
/// interval. Client has the default value of each parameters, they are only saved in
61-
/// internalMetadata if they have been customize by developers.
62-
@property(nonatomic, readonly, copy) NSDictionary *internalMetadata;
6358
/// Device conditions since last successful fetch from the backend. Device conditions including
6459
/// app
6560
/// version, iOS version, device localte, language, GMP project ID and Game project ID. Used for
@@ -122,9 +117,6 @@
122117
/// Returns metadata from metadata table.
123118
- (NSDictionary *)loadConfigFromMetadataTable;
124119

125-
/// Updates internal content with the latest successful config response.
126-
- (void)updateInternalContentWithResponse:(NSDictionary *)response;
127-
128120
/// Updates the metadata table with the current fetch status.
129121
/// @param fetchSuccess True if fetch was successful.
130122
- (void)updateMetadataWithFetchSuccessStatus:(BOOL)fetchSuccess

FirebaseRemoteConfig/Sources/RCNConfigDBManager.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ typedef void (^RCNDBLoadCompletion)(BOOL success,
7070
/// start. Config settings include success/failure fetch times, device contenxt, app context, etc.
7171
- (NSDictionary *)loadMetadataWithBundleIdentifier:(NSString *)bundleIdentifier
7272
namespace:(NSString *)namespace;
73-
/// Load internal metadata from internal metadata table, such as customized HTTP connection/read
74-
/// timeout, throttling time interval and number limit of throttling, etc.
75-
/// This call needs to be blocking to ensure throttling works during apps starts.
76-
- (NSDictionary *)loadInternalMetadataTable;
7773
/// Load experiment from experiment table.
7874
/// @param handler The callback when reading from DB is complete.
7975
- (void)loadExperimentWithCompletionHandler:(RCNDBCompletion)handler;
@@ -90,10 +86,6 @@ typedef void (^RCNDBLoadCompletion)(BOOL success,
9086
- (void)insertMainTableWithValues:(NSArray *)values
9187
fromSource:(RCNDBSource)source
9288
completionHandler:(RCNDBCompletion)handler;
93-
/// Insert a record in internal metadata table.
94-
/// @param values Values to be inserted.
95-
- (void)insertInternalMetadataTableWithValues:(NSArray *)values
96-
completionHandler:(RCNDBCompletion)handler;
9789
/// Insert experiment data in experiment table.
9890
/// @param key The key of experiment data belongs to, which are defined in
9991
/// RCNConfigDefines.h.
@@ -125,11 +117,10 @@ typedef void (^RCNDBLoadCompletion)(BOOL success,
125117
- (void)deleteRecordFromMainTableWithNamespace:(NSString *)namespace_p
126118
bundleIdentifier:(NSString *)bundleIdentifier
127119
fromSource:(RCNDBSource)source;
128-
/// Remove all the records of given package name and namespace from metadata/internal metadata DB
120+
/// Remove all the records of given package name and namespace from metadata DB
129121
/// before updating new values from response.
130122
- (void)deleteRecordWithBundleIdentifier:(NSString *)bundlerIdentifier
131-
namespace:(NSString *)namespace
132-
isInternalDB:(BOOL)isInternalDB;
123+
namespace:(NSString *)namespace;
133124
/// Remove all the records from a config content table.
134125
- (void)deleteAllRecordsFromTableWithSource:(RCNDBSource)source;
135126

FirebaseRemoteConfig/Sources/RCNConfigDBManager.m

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#define RCNTableNameMainDefault "main_default"
2929
#define RCNTableNameMetadataDeprecated "fetch_metadata"
3030
#define RCNTableNameMetadata "fetch_metadata_v2"
31-
#define RCNTableNameInternalMetadata "internal_metadata"
3231
#define RCNTableNameExperiment "experiment"
3332
#define RCNTableNamePersonalization "personalization"
3433
#define RCNTableNameRollout "rollout"
@@ -278,10 +277,6 @@ - (BOOL)createTableSchema {
278277
"success_fetch_time BLOB, failure_fetch_time BLOB, last_fetch_status INTEGER, "
279278
"last_fetch_error INTEGER, last_apply_time INTEGER, last_set_defaults_time INTEGER)";
280279

281-
static const char *createTableInternalMetadata =
282-
"create TABLE IF NOT EXISTS " RCNTableNameInternalMetadata
283-
" (_id INTEGER PRIMARY KEY, key TEXT, value BLOB)";
284-
285280
static const char *createTableExperiment = "create TABLE IF NOT EXISTS " RCNTableNameExperiment
286281
" (_id INTEGER PRIMARY KEY, key TEXT, value BLOB)";
287282
static const char *createTablePersonalization =
@@ -293,7 +288,6 @@ - (BOOL)createTableSchema {
293288

294289
return [self executeQuery:createTableMain] && [self executeQuery:createTableMainActive] &&
295290
[self executeQuery:createTableMainDefault] && [self executeQuery:createTableMetadata] &&
296-
[self executeQuery:createTableInternalMetadata] &&
297291
[self executeQuery:createTableExperiment] &&
298292
[self executeQuery:createTablePersonalization] && [self executeQuery:createTableRollout];
299293
}
@@ -471,48 +465,6 @@ - (BOOL)insertMainTableWithValues:(NSArray *)values fromSource:(RCNDBSource)sour
471465
return YES;
472466
}
473467

474-
- (void)insertInternalMetadataTableWithValues:(NSArray *)values
475-
completionHandler:(RCNDBCompletion)handler {
476-
__weak RCNConfigDBManager *weakSelf = self;
477-
dispatch_async(_databaseOperationQueue, ^{
478-
BOOL success = [weakSelf insertInternalMetadataWithValues:values];
479-
if (handler) {
480-
dispatch_async(dispatch_get_main_queue(), ^{
481-
handler(success, nil);
482-
});
483-
}
484-
});
485-
}
486-
487-
- (BOOL)insertInternalMetadataWithValues:(NSArray *)values {
488-
RCN_MUST_NOT_BE_MAIN_THREAD();
489-
if (values.count != 2) {
490-
return NO;
491-
}
492-
const char *SQL =
493-
"INSERT OR REPLACE INTO " RCNTableNameInternalMetadata " (key, value) values (?, ?)";
494-
sqlite3_stmt *statement = [self prepareSQL:SQL];
495-
if (!statement) {
496-
return NO;
497-
}
498-
NSString *aString = values[0];
499-
if (![self bindStringToStatement:statement index:1 string:aString]) {
500-
[self logErrorWithSQL:SQL finalizeStatement:statement returnValue:NO];
501-
return NO;
502-
}
503-
NSData *blobData = values[1];
504-
if (sqlite3_bind_blob(statement, 2, blobData.bytes, (int)blobData.length, NULL) != SQLITE_OK) {
505-
[self logErrorWithSQL:SQL finalizeStatement:statement returnValue:NO];
506-
return NO;
507-
}
508-
if (sqlite3_step(statement) != SQLITE_DONE) {
509-
[self logErrorWithSQL:SQL finalizeStatement:statement returnValue:NO];
510-
return NO;
511-
}
512-
sqlite3_finalize(statement);
513-
return YES;
514-
}
515-
516468
- (void)insertExperimentTableWithKey:(NSString *)key
517469
value:(NSData *)serializedValue
518470
completionHandler:(RCNDBCompletion)handler {
@@ -1039,34 +991,6 @@ - (NSData *)loadPersonalizationTableFromKey:(int)key {
1039991
return results[0];
1040992
}
1041993

1042-
- (NSDictionary *)loadInternalMetadataTable {
1043-
__block NSMutableDictionary *internalMetadataTableResult;
1044-
__weak RCNConfigDBManager *weakSelf = self;
1045-
dispatch_sync(_databaseOperationQueue, ^{
1046-
internalMetadataTableResult = [weakSelf loadInternalMetadataTableInternal];
1047-
});
1048-
return internalMetadataTableResult;
1049-
}
1050-
1051-
- (NSMutableDictionary *)loadInternalMetadataTableInternal {
1052-
NSMutableDictionary *internalMetadata = [[NSMutableDictionary alloc] init];
1053-
const char *SQL = "SELECT key, value FROM " RCNTableNameInternalMetadata;
1054-
sqlite3_stmt *statement = [self prepareSQL:SQL];
1055-
if (!statement) {
1056-
return nil;
1057-
}
1058-
1059-
while (sqlite3_step(statement) == SQLITE_ROW) {
1060-
NSString *key = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
1061-
1062-
NSData *dataValue = [NSData dataWithBytes:(char *)sqlite3_column_blob(statement, 1)
1063-
length:sqlite3_column_bytes(statement, 1)];
1064-
internalMetadata[key] = dataValue;
1065-
}
1066-
sqlite3_finalize(statement);
1067-
return internalMetadata;
1068-
}
1069-
1070994
/// This method is only meant to be called at init time. The underlying logic will need to be
1071995
/// reevaluated if the assumption changes at a later time.
1072996
- (void)loadMainWithBundleIdentifier:(NSString *)bundleIdentifier
@@ -1178,20 +1102,16 @@ - (void)deleteRecordFromMainTableWithNamespace:(NSString *)namespace_p
11781102
}
11791103

11801104
- (void)deleteRecordWithBundleIdentifier:(NSString *)bundleIdentifier
1181-
namespace:(NSString *)namespace
1182-
isInternalDB:(BOOL)isInternalDB {
1105+
namespace:(NSString *)namespace {
11831106
__weak RCNConfigDBManager *weakSelf = self;
11841107
dispatch_async(_databaseOperationQueue, ^{
11851108
RCNConfigDBManager *strongSelf = weakSelf;
11861109
if (!strongSelf) {
11871110
return;
11881111
}
1189-
const char *SQL = "DELETE FROM " RCNTableNameInternalMetadata " WHERE key LIKE ?";
1190-
NSArray *params = @[ bundleIdentifier ];
1191-
if (!isInternalDB) {
1192-
SQL = "DELETE FROM " RCNTableNameMetadata " WHERE bundle_identifier = ? and namespace = ?";
1193-
params = @[ bundleIdentifier, namespace ];
1194-
}
1112+
const char *SQL =
1113+
"DELETE FROM " RCNTableNameMetadata " WHERE bundle_identifier = ? and namespace = ?";
1114+
NSArray *params = @[ bundleIdentifier, namespace ];
11951115
[strongSelf executeQuery:SQL withParams:params];
11961116
});
11971117
}

FirebaseRemoteConfig/Sources/RCNConfigSettings.m

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ @interface RCNConfigSettings () {
4545
/// Custom variables (aka App context digest). This is the pending custom variables request before
4646
/// fetching.
4747
NSMutableDictionary *_customVariables;
48-
/// Cached internal metadata from internal metadata table. It contains customized information such
49-
/// as HTTP connection timeout, HTTP read timeout, success/failure throttling rate and time
50-
/// interval. Client has the default value of each parameters, they are only saved in
51-
/// internalMetadata if they have been customize by developers.
52-
NSMutableDictionary *_internalMetadata;
5348
/// Last fetch status.
5449
FIRRemoteConfigFetchStatus _lastFetchStatus;
5550
/// Last fetch Error.
@@ -66,8 +61,6 @@ @interface RCNConfigSettings () {
6661
NSString *_googleAppID;
6762
/// The user defaults manager scoped to this RC instance of FIRApp and namespace.
6863
RCNUserDefaultsManager *_userDefaultsManager;
69-
/// The timestamp of last eTag update.
70-
NSTimeInterval _lastETagUpdateTime;
7164
}
7265
@end
7366

@@ -93,11 +86,6 @@ - (instancetype)initWithDatabaseManager:(RCNConfigDBManager *)manager
9386
_successFetchTimes = [[NSMutableArray alloc] init];
9487
_failureFetchTimes = [[NSMutableArray alloc] init];
9588
_DBManager = manager;
96-
97-
_internalMetadata = [[_DBManager loadInternalMetadataTable] mutableCopy];
98-
if (!_internalMetadata) {
99-
_internalMetadata = [[NSMutableDictionary alloc] init];
100-
}
10189
_userDefaultsManager = [[RCNUserDefaultsManager alloc] initWithAppName:appName
10290
bundleID:_bundleIdentifier
10391
namespace:_FIRNamespace];
@@ -184,32 +172,6 @@ - (NSDictionary *)loadConfigFromMetadataTable {
184172
}
185173

186174
#pragma mark - update DB/cached
187-
188-
// Update internal metadata content to cache and DB.
189-
- (void)updateInternalContentWithResponse:(NSDictionary *)response {
190-
// Remove all the keys with current package name.
191-
[_DBManager deleteRecordWithBundleIdentifier:_bundleIdentifier
192-
namespace:_FIRNamespace
193-
isInternalDB:YES];
194-
195-
for (NSString *key in _internalMetadata.allKeys) {
196-
if ([key hasPrefix:_bundleIdentifier]) {
197-
[_internalMetadata removeObjectForKey:key];
198-
}
199-
}
200-
201-
for (NSString *entry in response) {
202-
NSData *val = [response[entry] dataUsingEncoding:NSUTF8StringEncoding];
203-
NSArray *values = @[ entry, val ];
204-
_internalMetadata[entry] = response[entry];
205-
[self updateInternalMetadataTableWithValues:values];
206-
}
207-
}
208-
209-
- (void)updateInternalMetadataTableWithValues:(NSArray *)values {
210-
[_DBManager insertInternalMetadataTableWithValues:values completionHandler:nil];
211-
}
212-
213175
/// If the last fetch was not successful, update the (exponential backoff) period that we wait until
214176
/// fetching again. Any subsequent fetch requests will be checked and allowed only if past this
215177
/// throttle end time.
@@ -310,9 +272,7 @@ - (void)updateFetchTimeWithSuccessFetch:(BOOL)isSuccessfulFetch {
310272
}
311273

312274
- (void)updateMetadataTable {
313-
[_DBManager deleteRecordWithBundleIdentifier:_bundleIdentifier
314-
namespace:_FIRNamespace
315-
isInternalDB:NO];
275+
[_DBManager deleteRecordWithBundleIdentifier:_bundleIdentifier namespace:_FIRNamespace];
316276
NSError *error;
317277
// Objects to be serialized cannot be invalid.
318278
if (!_bundleIdentifier) {
@@ -472,10 +432,6 @@ - (NSDictionary *)customVariables {
472432
return [_customVariables copy];
473433
}
474434

475-
- (NSDictionary *)internalMetadata {
476-
return [_internalMetadata copy];
477-
}
478-
479435
- (NSDictionary *)deviceContext {
480436
return [_deviceContext copy];
481437
}

FirebaseRemoteConfig/Tests/Unit/RCNConfigDBManagerTest.m

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -155,39 +155,6 @@ - (void)testWriteAndLoadMainTableResult {
155155
}];
156156
}
157157

158-
- (void)testWriteAndLoadInternalMetadataResult {
159-
XCTestExpectation *loadConfigContentExpectation = [self
160-
expectationWithDescription:@"Write and read internal metadata in database successfully"];
161-
__block int count = 0;
162-
for (int i = 0; i <= 100; ++i) {
163-
// check DB write correctly
164-
RCNDBCompletion insertCompletion = ^void(BOOL success, NSDictionary *result) {
165-
count++;
166-
XCTAssertTrue(success);
167-
if (count == 100) {
168-
// check DB read correctly
169-
NSDictionary *result = [self->_DBManager loadInternalMetadataTable];
170-
NSString *stringValue = [[NSString alloc] initWithData:result[@"key100"]
171-
encoding:NSUTF8StringEncoding];
172-
XCTAssertEqualObjects(stringValue, @"value100");
173-
if (success) {
174-
[loadConfigContentExpectation fulfill];
175-
}
176-
}
177-
};
178-
NSString *value = [NSString stringWithFormat:@"value%d", i];
179-
NSString *key = [NSString stringWithFormat:@"key%d", i];
180-
181-
NSArray *values = @[ key, [value dataUsingEncoding:NSUTF8StringEncoding] ];
182-
[_DBManager insertInternalMetadataTableWithValues:values completionHandler:insertCompletion];
183-
}
184-
185-
[self waitForExpectationsWithTimeout:_expectionTimeout
186-
handler:^(NSError *error) {
187-
XCTAssertNil(error);
188-
}];
189-
}
190-
191158
- (void)testWriteAndLoadMetadataResult {
192159
XCTestExpectation *writeAndLoadMetadataExpectation =
193160
[self expectationWithDescription:@"Write and load metadata in database successfully"];

0 commit comments

Comments
 (0)