diff --git a/LKDBHelper/Helper/LKDBHelper.m b/LKDBHelper/Helper/LKDBHelper.m index 4ea6506..c6152b2 100644 --- a/LKDBHelper/Helper/LKDBHelper.m +++ b/LKDBHelper/Helper/LKDBHelper.m @@ -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 { @@ -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; @@ -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) {