Skip to content

Commit

Permalink
fix: GrowingEventManager 在 loadLocalServices 之前初始化将导致数据库创建失败,事件无法入库
Browse files Browse the repository at this point in the history
  • Loading branch information
YoloMao committed Apr 6, 2022
1 parent abccc9c commit 5a0b314
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@

+ (_Nonnull instancetype)sharedInstance;

/// 配置事件发送通道
- (void)configChannels;
/// 配置事件管理者
- (void)configManager;

/// 开启事件发送定时器
- (void)startTimerSend;
Expand Down
31 changes: 14 additions & 17 deletions GrowingAnalytics/GrowingTrackerCore/Event/GrowingEventManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,35 @@ + (instancetype)sharedInstance {
- (instancetype)init {
if (self = [super init]) {
_allInterceptor = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
_packageNum = kGrowingMaxBatchSize;
// default is 10MB
_uploadLimitOfCellular = [GrowingConfigurationManager sharedInstance].trackConfiguration.cellularDataLimit * kGrowingUnit_MB;
[GrowingDispatchManager dispatchInGrowingThread:^{
self->_timingEventDB = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath]];
self->_timingEventDB.autoFlushCount = kGrowingMaxDBCacheSize;

self->_realtimeEventDB = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getRealtimeDatabasePath]];

// clean expired event data
[self cleanExpiredData_unsafe];
// load eventQueue for the first time
[self reloadFromDB_unsafe];
}];
}
return self;
}

#pragma mark - Configure Channels
#pragma mark - Configure Manager

- (void)configChannels {
- (void)configManager {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[GrowingDispatchManager dispatchInGrowingThread:^{
self->_packageNum = kGrowingMaxBatchSize;
// default is 10MB
self->_uploadLimitOfCellular = [GrowingConfigurationManager sharedInstance].trackConfiguration.cellularDataLimit * kGrowingUnit_MB;

self->_timingEventDB = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath]];
self->_timingEventDB.autoFlushCount = kGrowingMaxDBCacheSize;
self->_realtimeEventDB = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getRealtimeDatabasePath]];
// clean expired event data
[self cleanExpiredData_unsafe];
// load eventQueue for the first time
[self reloadFromDB_unsafe];

for (NSObject<GrowingEventInterceptor> *obj in self.allInterceptor) {
if ([obj respondsToSelector:@selector(growingEventManagerChannels:)]) {
[obj growingEventManagerChannels:[GrowingEventChannel eventChannels]];
}
}

self->_allEventChannels = [GrowingEventChannel buildAllEventChannels];

self->_eventChannelDict = [GrowingEventChannel eventChannelMapFromAllChannels:self->_allEventChannels];
// all other events got to this category
self->_otherEventChannel = [GrowingEventChannel otherEventChannelFromAllChannels:self->_allEventChannels];
Expand Down
2 changes: 1 addition & 1 deletion GrowingAnalytics/GrowingTrackerCore/GrowingRealTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (instancetype)initWithConfiguration:(GrowingTrackConfiguration *)configuration
[[GrowingServiceManager sharedInstance] loadLocalServices];
[[GrowingModuleManager sharedInstance] triggerEvent:GrowingMInitEvent];
// 各个Module初始化init之后再进行事件定时发送
[[GrowingEventManager sharedInstance] configChannels];
[[GrowingEventManager sharedInstance] configManager];
[[GrowingEventManager sharedInstance] startTimerSend];
[self versionPrint];
[self filterLogPrint];
Expand Down

0 comments on commit 5a0b314

Please sign in to comment.