diff --git a/Classes/BITChannel.h b/Classes/BITChannel.h index 3ee92994f9..3b9c938319 100644 --- a/Classes/BITChannel.h +++ b/Classes/BITChannel.h @@ -70,10 +70,13 @@ FOUNDATION_EXPORT char *BITSafeJsonEventsString; @property (nonatomic, assign) NSUInteger dataItemCount; /** - * A timer source which is used to flush the queue after a cretain time. + * Initializes a new BITChannel instance. + * + * @param telemetryContext the context used to add context values to the metrics payload + * @param persistence the persistence used to save metrics after the queue gets flushed + * + * @return the telemetry context */ -@property (nonatomic, strong, null_unspecified) dispatch_source_t timerSource; - - (instancetype)initWithTelemetryContext:(BITTelemetryContext *)telemetryContext persistence:(BITPersistence *) persistence; /** @@ -110,16 +113,6 @@ void bit_appendStringToSafeJsonStream(NSString *string, char *__nonnull*__nonnul */ void bit_resetSafeJsonStream(char *__nonnull*__nonnull jsonStream); -/** - * Starts the timer. - */ -- (void)startTimer; - -/** - * Stops the timer if currently running. - */ -- (void)invalidateTimer; - /** * A method which indicates whether the telemetry pipeline is busy and no new data should be enqueued. * Currently, we drop telemetry data if this returns YES. diff --git a/Classes/BITChannel.m b/Classes/BITChannel.m index 867540644b..0b8acd9f14 100644 --- a/Classes/BITChannel.m +++ b/Classes/BITChannel.m @@ -16,8 +16,7 @@ static char *const BITDataItemsOperationsQueue = "net.hockeyapp.senderQueue"; char *BITSafeJsonEventsString; -NSInteger const defaultBatchInterval = 20; -NSInteger const defaultMaxBatchCount = 50; +NSInteger const defaultMaxBatchCount = 1; static NSInteger const schemaVersion = 2; @implementation BITChannel @@ -53,7 +52,6 @@ static NSInteger const schemaVersion = 2; } - (void)persistDataItemQueue { - [self invalidateTimer]; if(!BITSafeJsonEventsString || strlen(BITSafeJsonEventsString) == 0) { return; } @@ -87,9 +85,6 @@ static NSInteger const schemaVersion = 2; // Max batch count has been reached, so write queue to disk and delete all items. [strongSelf persistDataItemQueue]; - } else if(strongSelf->_dataItemCount == 1) { - // It is the first item, let's start the timer - [strongSelf startTimer]; } }); } @@ -187,30 +182,6 @@ void bit_resetSafeJsonStream(char **string) { #pragma mark - Batching -- (void)invalidateTimer { - if(self.timerSource) { - dispatch_source_cancel(self.timerSource); - self.timerSource = nil; - } -} - -- (void)startTimer { - - // Reset timer, if it is already running - if(self.timerSource) { - [self invalidateTimer]; - } - - self.timerSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, self.dataItemsOperations); - dispatch_source_set_timer(self.timerSource, dispatch_walltime(NULL, NSEC_PER_SEC * defaultBatchInterval), 1ull * NSEC_PER_SEC, 1ull * NSEC_PER_SEC); - dispatch_source_set_event_handler(self.timerSource, ^{ - - // On completion: Reset timer and persist items - [self persistDataItemQueue]; - }); - dispatch_resume(self.timerSource); -} - - (NSInteger)maxBatchCount { if(_maxBatchCount <= 0){ return defaultMaxBatchCount; diff --git a/Support/HockeySDKTests/BITChannelTests.m b/Support/HockeySDKTests/BITChannelTests.m index e03911c1a7..6ccd654de6 100644 --- a/Support/HockeySDKTests/BITChannelTests.m +++ b/Support/HockeySDKTests/BITChannelTests.m @@ -45,6 +45,7 @@ - (void)testEnqueueEnvelopeWithOneEnvelopeAndJSONStream { _sut = OCMPartialMock(_sut); + _sut.maxBatchCount = 3; BITTelemetryData *testData = [BITTelemetryData new]; [_sut enqueueTelemetryItem:testData]; @@ -52,7 +53,6 @@ dispatch_sync(_sut.dataItemsOperations, ^{ assertThatUnsignedInteger(_sut.dataItemCount, equalToUnsignedInteger(1)); XCTAssertTrue(strlen(BITSafeJsonEventsString) > 0); - OCMVerify([_sut startTimer]); }); } @@ -78,7 +78,6 @@ [_sut enqueueTelemetryItem:testData]; dispatch_sync(_sut.dataItemsOperations, ^{ - OCMVerify([_sut invalidateTimer]); assertThatUnsignedInteger(_sut.dataItemCount, equalToUnsignedInteger(0)); XCTAssertTrue(strcmp(BITSafeJsonEventsString, "") == 0); });