Commit a95c7555 authored by 翟国钧's avatar 翟国钧

增加一个专门负责发送数据的方法,修改边界情况下的bug:当cache中的数据满50条发送给服务器的时候,再有数据过来,会重复发送

parent 26d9c677
PODS: PODS:
- GMCache (0.1.1): - GMCache (0.1.1):
- TMCache (~> 2.1.0) - TMCache (~> 2.1.0)
- GMPhobos (0.3.6): - GMPhobos (0.3.7):
- GMCache (~> 0.1.1) - GMCache (~> 0.1.1)
- TMCache (2.1.0) - TMCache (2.1.0)
...@@ -14,7 +14,7 @@ EXTERNAL SOURCES: ...@@ -14,7 +14,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
GMCache: 73855b613b9d7e34f4f37ad425e8b8153b760c04 GMCache: 73855b613b9d7e34f4f37ad425e8b8153b760c04
GMPhobos: a7e9b181f903becb1135b5f058f80353fe3dd784 GMPhobos: 57d155e2b1e64934b8507c275d6dbe53b1631457
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM: 281ed5ce2f0e8e2e49cc13b1e4726e6686ac6095 PODFILE CHECKSUM: 281ed5ce2f0e8e2e49cc13b1e4726e6686ac6095
......
{ {
"name": "GMPhobos", "name": "GMPhobos",
"version": "0.3.6", "version": "0.3.7",
"summary": "GM statistic data sdk", "summary": "GM statistic data sdk",
"description": "GM event track sdk.", "description": "GM event track sdk.",
"homepage": "http://git.gengmei.cc/gengmeiios/GMPhobos", "homepage": "http://git.gengmei.cc/gengmeiios/GMPhobos",
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
}, },
"source": { "source": {
"git": "git@git.gengmei.cc:gengmeiios/GMPhobos.git", "git": "git@git.gengmei.cc:gengmeiios/GMPhobos.git",
"tag": "0.3.6" "tag": "0.3.7"
}, },
"platforms": { "platforms": {
"ios": "8.0" "ios": "8.0"
......
PODS: PODS:
- GMCache (0.1.1): - GMCache (0.1.1):
- TMCache (~> 2.1.0) - TMCache (~> 2.1.0)
- GMPhobos (0.3.6): - GMPhobos (0.3.7):
- GMCache (~> 0.1.1) - GMCache (~> 0.1.1)
- TMCache (2.1.0) - TMCache (2.1.0)
...@@ -14,7 +14,7 @@ EXTERNAL SOURCES: ...@@ -14,7 +14,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
GMCache: 73855b613b9d7e34f4f37ad425e8b8153b760c04 GMCache: 73855b613b9d7e34f4f37ad425e8b8153b760c04
GMPhobos: a7e9b181f903becb1135b5f058f80353fe3dd784 GMPhobos: 57d155e2b1e64934b8507c275d6dbe53b1631457
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM: 281ed5ce2f0e8e2e49cc13b1e4726e6686ac6095 PODFILE CHECKSUM: 281ed5ce2f0e8e2e49cc13b1e4726e6686ac6095
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.3.6</string> <string>0.3.7</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -404,26 +404,21 @@ static NSString *sdkVersion = @"110"; ...@@ -404,26 +404,21 @@ static NSString *sdkVersion = @"110";
} }
} }
/** /*
向Mars发送埋点数据,如果是实时发送的,http请求成功之后,不清楚已有的缓存数据。 从缓存区获取数据,发给服务器,请求成功的时候,把缓存区的数据删除掉
针对普通埋点数据,发送成功之后,立即删除本地的缓存。
@author zhaiguojun 16-10-17 in (null)
@param array 参数
@param now 是否立即清楚缓存
*/ */
- (void)sendArray:(NSArray *)array cleanCacheRightNow:(BOOL)clean { - (void)sendArray {
NSMutableArray *dataArray = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosTempCacheKey];
if (_logEnabled) { if (_logEnabled) {
phobosLog([NSString stringWithFormat:@"array prepare to fly --✈: %@",array]); phobosLog([NSString stringWithFormat:@"array prepare to fly --✈: %@",dataArray]);
} }
@try { @try {
NSData *JSON = [PhobosUtil encodeJSON:array]; NSData *JSON = [PhobosUtil encodeJSON:dataArray];
NSData *compressedData = [PhobosUtil compressData:JSON]; NSData *compressedData = [PhobosUtil compressData:JSON];
if (compressedData) { if (compressedData) {
[PhobosUtil sendData:compressedData success:^(NSInteger code) { [PhobosUtil sendData:compressedData success:^(NSInteger code) {
phobosLog(@"✈ ---------- ✈ data arrived Mars"); phobosLog(@"✈ ---------- ✈ data arrived Mars");
if (clean) { [[WMCacheService sharedInstance] removeObjectAtDiskWithkey:PhobosTempCacheKey];
[[WMCacheService sharedInstance] removeObjectAtDiskWithkey:PhobosCacheKey];
}
}]; }];
} }
} }
...@@ -432,6 +427,34 @@ static NSString *sdkVersion = @"110"; ...@@ -432,6 +427,34 @@ static NSString *sdkVersion = @"110";
} }
} }
/**
该方法有改动,现在的逻辑是:当前方法只接受发送的请求,然后把数据转存到另一个缓存区,
让sendArray方法负责发送,数据一旦转移到缓存区,就把原有的数据干掉。
@author zhaiguojun 16-10-17 in (null)
@param array 参数
@param now 是否立即清楚缓存
*/
- (void)sendArray:(NSArray *)array cleanCacheRightNow:(BOOL)clean {
@try {
//1.获取缓存区的数据,把新数据追加进去
WMCacheService *cache = [WMCacheService sharedInstance];
NSMutableArray *dataArray = [cache fetchObjectAtDiskWithkey:PhobosTempCacheKey];
if (dataArray) {
[dataArray addObjectsFromArray:array];
}else{
dataArray = [NSMutableArray arrayWithArray:array];
}
[cache storeObjectAtDiskWithkey:PhobosTempCacheKey object:dataArray];
//2.把缓存区的数据发送给服务器
[self sendArray];
//3.把原有的数据删除
[cache removeObjectAtDiskWithkey:PhobosCacheKey];
}
@catch (NSException *exception) {
phobosLog(exception);
}
}
#pragma mark - helpers #pragma mark - helpers
- (void)catchNullForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes { - (void)catchNullForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes {
dispatch_async(dispatch_get_global_queue(0, 0), ^{ dispatch_async(dispatch_get_global_queue(0, 0), ^{
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#define PhobosHaveOpenApp @"PhobosHaveOpenApp" //是否打开过APP #define PhobosHaveOpenApp @"PhobosHaveOpenApp" //是否打开过APP
#define PhobosBeginTime @"PhobosBeginTime" //记录APP打开|从后台启动时的时间戳 #define PhobosBeginTime @"PhobosBeginTime" //记录APP打开|从后台启动时的时间戳
#define PhobosEndTime @"PhobosEndTime" //记录APP退出|退到后台时的时间戳 #define PhobosEndTime @"PhobosEndTime" //记录APP退出|退到后台时的时间戳
#define PhobosCacheKey @"PhobosCacheKey" #define PhobosCacheKey @"PhobosCacheKey" //存放持久化埋点数据的key
#define PhobosTempCacheKey @"PhobosTempCacheKey" //临时存放待发送埋点数据的key
#define PhobosShardCount 50 //收集数据分段发送的个数 #define PhobosShardCount 50 //收集数据分段发送的个数
#endif /* PhobosConfig_h */ #endif /* PhobosConfig_h */
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