Skip to content

Commit

Permalink
修复 runAutoVacuumAction 没判断 时间阈值 的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lijianghuai committed Jan 25, 2022
1 parent 48b0f21 commit e0eb021
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions LKDBHelper/Helper/LKDBHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,13 @@ - (void)runAutoCloseDBConnection {
if (!self.autoCloseDBDelayTime) {
return;
}
// 超过阈值没有操作 关闭数据库链接
if (CFAbsoluteTimeGetCurrent() - self.lastExecuteDBTime > self.autoCloseDBDelayTime) {
[self closeDB];
// 判断阈值内是否有操作
const NSInteger nowTime = CFAbsoluteTimeGetCurrent();
if (nowTime - self.lastExecuteDBTime < self.autoCloseDBDelayTime) {
return;
}
// 关闭数据库链接
[self closeDB];
}

- (void)runAutoVacuumAction {
Expand All @@ -328,6 +331,11 @@ - (void)runAutoVacuumAction {
if (!self.enableAutoVacuum) {
return;
}
// 判断阈值内是否有操作
const NSInteger nowTime = CFAbsoluteTimeGetCurrent();
if (nowTime - self.lastExecuteDBTime < 10) {
return;
}
// 读取全局缓存文件
static NSMutableDictionary *dbAutoVaccumMap = nil;
static NSString *dbAutoVaccumPath = nil;
Expand All @@ -344,7 +352,6 @@ - (void)runAutoVacuumAction {
});
// 3天操作一次
NSString *dbKey = self.dbPath.lastPathComponent;
NSInteger nowTime = CFAbsoluteTimeGetCurrent();
dispatch_semaphore_wait(dbLock, DISPATCH_TIME_FOREVER);
NSInteger lastTime = [[dbAutoVaccumMap objectForKey:dbKey] integerValue];
if (0 == lastTime) {
Expand Down

0 comments on commit e0eb021

Please sign in to comment.