Skip to content

Commit

Permalink
[rc-swift] ConfigDBManager.swift (#14126)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Nov 22, 2024
1 parent b4e5bcf commit 06d4e4d
Show file tree
Hide file tree
Showing 27 changed files with 1,841 additions and 1,897 deletions.
152 changes: 76 additions & 76 deletions .github/workflows/remoteconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,83 +84,83 @@ jobs:
scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb ${{ matrix.podspec }} --platforms=${{ matrix.target }} \
${{ matrix.build-env.tests }}
spm-package-resolved:
env:
FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1
runs-on: macos-14
outputs:
cache_key: ${{ steps.generate_cache_key.outputs.cache_key }}
steps:
- uses: actions/checkout@v4
- name: Generate Swift Package.resolved
id: swift_package_resolve
run: |
swift package resolve
- name: Generate cache key
id: generate_cache_key
run: |
cache_key="${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}"
echo "cache_key=${cache_key}" >> "$GITHUB_OUTPUT"
- uses: actions/cache/save@v4
id: cache
with:
path: .build
key: ${{ steps.generate_cache_key.outputs.cache_key }}
# spm-package-resolved:
# env:
# FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1
# runs-on: macos-14
# outputs:
# cache_key: ${{ steps.generate_cache_key.outputs.cache_key }}
# steps:
# - uses: actions/checkout@v4
# - name: Generate Swift Package.resolved
# id: swift_package_resolve
# run: |
# swift package resolve
# - name: Generate cache key
# id: generate_cache_key
# run: |
# cache_key="${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}"
# echo "cache_key=${cache_key}" >> "$GITHUB_OUTPUT"
# - uses: actions/cache/save@v4
# id: cache
# with:
# path: .build
# key: ${{ steps.generate_cache_key.outputs.cache_key }}

spm:
# Don't run on private repo unless it is a PR.
if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
needs: [spm-package-resolved]
strategy:
matrix:
include:
- os: macos-13
xcode: Xcode_15.2
target: iOS
test: spm
- os: macos-14
xcode: Xcode_15.4
target: iOS
test: spm
- os: macos-15
xcode: Xcode_16.1
target: iOS
test: spm
- os: macos-15
xcode: Xcode_16.1
target: tvOS
test: spm
- os: macos-15
xcode: Xcode_16.1
target: macOS
test: spm
- os: macos-15
xcode: Xcode_16.1
target: watchOS
test: spmbuildonly
- os: macos-15
xcode: Xcode_16.1
target: catalyst
test: spm
- os: macos-15
xcode: Xcode_16.1
target: visionOS
test: spm
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache/restore@v4
with:
path: .build
key: ${{needs.spm-package-resolved.outputs.cache_key}}
- name: Xcode
run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer
- name: Initialize xcodebuild
run: scripts/setup_spm_tests.sh
- name: Unit Tests
run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigUnit ${{ matrix.target }} spm
- name: Fake Console tests
run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigFakeConsole ${{ matrix.target }} ${{ matrix.test }}
# spm:
# # Don't run on private repo unless it is a PR.
# if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
# needs: [spm-package-resolved]
# strategy:
# matrix:
# include:
# - os: macos-13
# xcode: Xcode_15.2
# target: iOS
# test: spm
# - os: macos-14
# xcode: Xcode_15.4
# target: iOS
# test: spm
# - os: macos-15
# xcode: Xcode_16.1
# target: iOS
# test: spm
# - os: macos-15
# xcode: Xcode_16.1
# target: tvOS
# test: spm
# - os: macos-15
# xcode: Xcode_16.1
# target: macOS
# test: spm
# - os: macos-15
# xcode: Xcode_16.1
# target: watchOS
# test: spmbuildonly
# - os: macos-15
# xcode: Xcode_16.1
# target: catalyst
# test: spm
# - os: macos-15
# xcode: Xcode_16.1
# target: visionOS
# test: spm
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v4
# - uses: actions/cache/restore@v4
# with:
# path: .build
# key: ${{needs.spm-package-resolved.outputs.cache_key}}
# - name: Xcode
# run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer
# - name: Initialize xcodebuild
# run: scripts/setup_spm_tests.sh
# - name: Unit Tests
# run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigUnit ${{ matrix.target }} spm
# - name: Fake Console tests
# run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigFakeConsole ${{ matrix.target }} ${{ matrix.test }}

catalyst:
# Don't run on private repo unless it is a PR.
Expand Down
1 change: 1 addition & 0 deletions FirebaseRemoteConfig.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ app update.
s.dependency 'FirebaseABTesting', '~> 11.0'
s.dependency 'FirebaseSharedSwift', '~> 11.0'
s.dependency 'FirebaseCore', '~> 11.6.0'
s.dependency 'FirebaseCoreExtension', '~> 11.6.0'
s.dependency 'FirebaseInstallations', '~> 11.0'
s.dependency 'GoogleUtilities/Environment', '~> 8.0'
s.dependency 'GoogleUtilities/NSData+zlib', '~> 8.0'
Expand Down
2 changes: 1 addition & 1 deletion FirebaseRemoteConfig/Sources/FIRConfigValue.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @implementation FIRRemoteConfigValue {
}

/// Designated initializer
- (instancetype)initWithData:(NSData *)data source:(FIRRemoteConfigSource)source {
- (instancetype)initWithData:(nullable NSData *)data source:(FIRRemoteConfigSource)source {
self = [super init];
if (self) {
_data = [data copy];
Expand Down
20 changes: 18 additions & 2 deletions FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigContent.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigDBManager.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigExperiment.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigRealtime.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
Expand Down Expand Up @@ -142,6 +141,7 @@ - (instancetype)initWithAppName:(NSString *)appName
namespace:(NSString *)FIRNamespace
DBManager:(RCNConfigDBManager *)DBManager
configContent:(RCNConfigContent *)configContent
userDefaults:(nullable NSUserDefaults *)userDefaults
analytics:(nullable id<FIRAnalyticsInterop>)analytics {
self = [super init];
if (self) {
Expand All @@ -155,7 +155,8 @@ - (instancetype)initWithAppName:(NSString *)appName
_settings = [[RCNConfigSettings alloc] initWithDatabaseManager:_DBManager
namespace:_FIRNamespace
firebaseAppName:appName
googleAppID:options.googleAppID];
googleAppID:options.googleAppID
userDefaults:userDefaults];

FIRExperimentController *experimentController = [FIRExperimentController sharedInstance];
_configExperiment = [[RCNConfigExperiment alloc] initWithDBManager:_DBManager
Expand Down Expand Up @@ -193,6 +194,21 @@ - (instancetype)initWithAppName:(NSString *)appName
return self;
}

- (instancetype)initWithAppName:(NSString *)appName
FIROptions:(FIROptions *)options
namespace:(NSString *)FIRNamespace
DBManager:(RCNConfigDBManager *)DBManager
configContent:(RCNConfigContent *)configContent
analytics:(nullable id<FIRAnalyticsInterop>)analytics {
return [self initWithAppName:appName
FIROptions:options
namespace:FIRNamespace
DBManager:DBManager
configContent:configContent
userDefaults:nil
analytics:analytics];
}

// Initialize with default config settings.
- (void)setDefaultConfigSettings {
// Set the default config settings.
Expand Down
3 changes: 2 additions & 1 deletion FirebaseRemoteConfig/Sources/FIRRemoteConfigComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"
#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigContent.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigDBManager.h"
#import "Interop/Analytics/Public/FIRAnalyticsInterop.h"

#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"

@implementation FIRRemoteConfigComponent

// Because Component now need to register two protocols (provider and interop), we need a way to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ NS_ASSUME_NONNULL_BEGIN
configContent:(RCNConfigContent *)configContent
analytics:(nullable id<FIRAnalyticsInterop>)analytics;

- (instancetype)initWithAppName:(NSString *)appName
FIROptions:(FIROptions *)options
namespace:(NSString *)FIRNamespace
DBManager:(RCNConfigDBManager *)DBManager
configContent:(RCNConfigContent *)configContent
userDefaults:(nullable NSUserDefaults *)userDefaults
analytics:(nullable id<FIRAnalyticsInterop>)analytics;

/// Register RolloutsStateSubcriber to FIRRemoteConfig instance
- (void)addRemoteConfigInteropSubscriber:(id<FIRRolloutsStateSubscriber> _Nonnull)subscriber;

Expand Down
18 changes: 8 additions & 10 deletions FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@class RCNConfigDBManager;

/// This internal class contains a set of variables that are unique among all the config instances.
/// It also handles all metadata and internal metadata. This class is not thread safe and does not
/// It also handles all metadata. This class is not thread safe and does not
/// inherently allow for synchronized access. Callers are responsible for synchronization
/// (currently using serial dispatch queues).
@interface RCNConfigSettings : NSObject
Expand Down 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 @@ -113,17 +108,20 @@
firebaseAppName:(NSString *)appName
googleAppID:(NSString *)googleAppID;

- (instancetype)initWithDatabaseManager:(RCNConfigDBManager *)manager
namespace:(NSString *)FIRNamespace
firebaseAppName:(NSString *)appName
googleAppID:(NSString *)googleAppID
userDefaults:(NSUserDefaults *)userDefaults;

/// Returns a fetch request with the latest device and config change.
/// Whenever user issues a fetch api call, collect the latest request.
/// @param userProperties User properties to set to config request.
/// @return Config fetch request string
- (NSString *)nextRequestWithUserProperties:(NSDictionary *)userProperties;

/// Returns metadata from metadata table.
- (NSDictionary *)loadConfigFromMetadataTable;

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

/// Updates the metadata table with the current fetch status.
/// @param fetchSuccess True if fetch was successful.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ NS_SWIFT_NAME(RemoteConfigValue)
@property(nonatomic, readonly, nullable) id JSONValue NS_SWIFT_NAME(jsonValue);
/// Identifies the source of the fetched value.
@property(nonatomic, readonly) FIRRemoteConfigSource source;

/// TODO: internal API for temporary bridging
/// Designated initializer.
- (instancetype _Nonnull)initWithData:(nullable NSData *)data
source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER;
@end

#pragma mark - FIRRemoteConfigSettings
Expand Down
7 changes: 1 addition & 6 deletions FirebaseRemoteConfig/Sources/RCNConfigContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@

#import <Foundation/Foundation.h>

#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"

typedef NS_ENUM(NSInteger, RCNDBSource) {
RCNDBSourceActive,
RCNDBSourceDefault,
RCNDBSourceFetched,
};

@class RCNConfigDBManager;

/// This class handles all the config content that is fetched from the server, cached in local
Expand Down
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Sources/RCNConfigContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h"
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigDBManager.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigDefines.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"

Expand Down
Loading

0 comments on commit 06d4e4d

Please sign in to comment.