Commit 2bd3fb25 authored by 井庆林's avatar 井庆林

code review

parent 2814756f
...@@ -39,6 +39,8 @@ static NSString *sdkVersion = @"1.3.0"; ...@@ -39,6 +39,8 @@ static NSString *sdkVersion = @"1.3.0";
static dispatch_semaphore_t _immediatelySemaphore; static dispatch_semaphore_t _immediatelySemaphore;
static dispatch_semaphore_t _normalSemaphore; static dispatch_semaphore_t _normalSemaphore;
static dispatch_queue_t _immediatelyQueue;
static dispatch_queue_t _normalQueue;
+ (Phobos *)clientWithAppName:(NSString *)appName channelId:(NSString *)channelId{ + (Phobos *)clientWithAppName:(NSString *)appName channelId:(NSString *)channelId{
Phobos.sharedClient.appName = appName; Phobos.sharedClient.appName = appName;
...@@ -51,6 +53,8 @@ static dispatch_semaphore_t _normalSemaphore; ...@@ -51,6 +53,8 @@ static dispatch_semaphore_t _normalSemaphore;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
_immediatelySemaphore = dispatch_semaphore_create(1); _immediatelySemaphore = dispatch_semaphore_create(1);
_normalSemaphore = dispatch_semaphore_create(1); _normalSemaphore = dispatch_semaphore_create(1);
_immediatelyQueue = dispatch_queue_create("immdiately", DISPATCH_QUEUE_CONCURRENT);
_normalQueue = dispatch_queue_create("normal", DISPATCH_QUEUE_CONCURRENT);
}); });
} }
...@@ -438,7 +442,7 @@ static dispatch_semaphore_t _normalSemaphore; ...@@ -438,7 +442,7 @@ static dispatch_semaphore_t _normalSemaphore;
} }
+ (void)track:(NSString *)eventName{ + (void)track:(NSString *)eventName{
[self track:eventName attributes:@{} sendNow:NO currentAPI:_sharedClient.serverAPI]; [self track:eventName attributes:nil sendNow:NO currentAPI:_sharedClient.serverAPI];
} }
+ (void)track:(NSString *)eventName attributes:(NSDictionary *)attributes{ + (void)track:(NSString *)eventName attributes:(NSDictionary *)attributes{
...@@ -450,7 +454,7 @@ static dispatch_semaphore_t _normalSemaphore; ...@@ -450,7 +454,7 @@ static dispatch_semaphore_t _normalSemaphore;
} }
+ (void)track:(NSString *)eventName currentAPI:(NSString *)currentAPI { + (void)track:(NSString *)eventName currentAPI:(NSString *)currentAPI {
[self track:eventName attributes:@{} sendNow:NO currentAPI:currentAPI]; [self track:eventName attributes:nil sendNow:NO currentAPI:currentAPI];
} }
+ (void)track:(NSString *)eventName attributes:(NSDictionary *)attributes currentAPI:(NSString *)currentAPI { + (void)track:(NSString *)eventName attributes:(NSDictionary *)attributes currentAPI:(NSString *)currentAPI {
...@@ -483,6 +487,7 @@ static dispatch_semaphore_t _normalSemaphore; ...@@ -483,6 +487,7 @@ static dispatch_semaphore_t _normalSemaphore;
} }
- (void)trackPhobosWithURL:(NSString *)url data:(NSDictionary *)data immediate:(BOOL)immediate { - (void)trackPhobosWithURL:(NSString *)url data:(NSDictionary *)data immediate:(BOOL)immediate {
dispatch_async(_normalQueue, ^{
dispatch_semaphore_wait(_normalSemaphore, DISPATCH_TIME_FOREVER); dispatch_semaphore_wait(_normalSemaphore, DISPATCH_TIME_FOREVER);
NSMutableDictionary *dataDict = [[GMCache fetchObjectAtDocumentPathWithkey:PhobosNormalCacheKey] mutableCopy]; NSMutableDictionary *dataDict = [[GMCache fetchObjectAtDocumentPathWithkey:PhobosNormalCacheKey] mutableCopy];
_normalCount++; _normalCount++;
...@@ -499,6 +504,7 @@ static dispatch_semaphore_t _normalSemaphore; ...@@ -499,6 +504,7 @@ static dispatch_semaphore_t _normalSemaphore;
[GMCache removeObjectAtDocumentPathWithkey:PhobosNormalCacheKey]; [GMCache removeObjectAtDocumentPathWithkey:PhobosNormalCacheKey];
} }
dispatch_semaphore_signal(_normalSemaphore); dispatch_semaphore_signal(_normalSemaphore);
});
} }
/** /**
...@@ -507,6 +513,7 @@ static dispatch_semaphore_t _normalSemaphore; ...@@ -507,6 +513,7 @@ static dispatch_semaphore_t _normalSemaphore;
* @param data : 使用id类型是因为直接调用实时埋点传过来的是Dict,而普通埋点过来的则是Array类型 * @param data : 使用id类型是因为直接调用实时埋点传过来的是Dict,而普通埋点过来的则是Array类型
*/ */
- (void)sendImmediatelyPhobosWithURL:(NSString *)url data:(id)data { - (void)sendImmediatelyPhobosWithURL:(NSString *)url data:(id)data {
dispatch_async(_immediatelyQueue, ^{
dispatch_semaphore_wait(_immediatelySemaphore, DISPATCH_TIME_FOREVER); dispatch_semaphore_wait(_immediatelySemaphore, DISPATCH_TIME_FOREVER);
__block NSMutableDictionary *dataDict = [[GMCache fetchObjectAtDocumentPathWithkey:PhobosImmediatelyCacheKey] mutableCopy]; __block NSMutableDictionary *dataDict = [[GMCache fetchObjectAtDocumentPathWithkey:PhobosImmediatelyCacheKey] mutableCopy];
dataDict = [self dataDict:dataDict setObject:data forKey:url]; dataDict = [self dataDict:dataDict setObject:data forKey:url];
...@@ -530,6 +537,7 @@ static dispatch_semaphore_t _normalSemaphore; ...@@ -530,6 +537,7 @@ static dispatch_semaphore_t _normalSemaphore;
phobosLog(@"✈ ---------- ✈ data arrived Mars"); phobosLog(@"✈ ---------- ✈ data arrived Mars");
}]; }];
}]; }];
});
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment