diff --git a/themes/beauty/controller/CommandController.php b/themes/beauty/controller/CommandController.php index bb5776b..902f239 100644 --- a/themes/beauty/controller/CommandController.php +++ b/themes/beauty/controller/CommandController.php @@ -10,6 +10,7 @@ Class CommandController extends Controller { protected $logPrefix = '[MainBot]'; protected $scanedDirCacheKey = 'MainBotScanedDirs'; protected $dateIndexCacheKey = 'MainBotDateIndex'; + protected $noOriginalCtimeFilesCacheKey = 'MainBotNoOriginalCtimeFiles'; public function actionIndex() { $commands = <<cleanScanCaches(); $this->scanMediaFiles(); $this->saveDateIndexIntoCacheFile(); + $this->saveNoOriginalCtimeFilesIntoFile(); //while (true) { //$time = date('Y-m-d H:i:s'); @@ -136,6 +138,7 @@ eof; protected function cleanScanCaches() { Common::setCache($this->scanedDirCacheKey, array()); Common::setCache($this->dateIndexCacheKey, array()); + Common::setCache($this->noOriginalCtimeFilesCacheKey, array()); } //扫描媒体文件:图片、视频、音乐 @@ -192,9 +195,11 @@ eof; $scanIndex ++; - //更新年份、月份时间索引 if (!empty($item['filename'])) { - $this->updateDateIndex($scanner, $item); + //更新年份、月份时间索引 + $this->updateDateIndex($item); + //更新没有拍摄时间的文件索引 + $this->updateNoOriginalCtimeFiles($item); } //更新扫描进度 @@ -249,7 +254,7 @@ eof; * 数据格式: * {"y2024": {"m1": [id1, id2, ...], "m10": [id1, id2, ...]}} */ - protected function updateDateIndex($scanner, $file) { + protected function updateDateIndex($file) { $ctime = !empty($file['original_ctime']) ? $file['original_ctime'] : $file['fstat']['ctime']; $cacheKey = $this->dateIndexCacheKey; @@ -267,6 +272,10 @@ eof; $cacheData[$year][$month] = array(); } + if (in_array($file['id'], $cacheData[$year][$month])) { + return false; + } + array_push($cacheData[$year][$month], $file['id']); return Common::setCache($cacheKey, $cacheData); @@ -296,8 +305,34 @@ eof; * 数据格式: * [id1, id2, ...] */ - protected function saveNoOriginalCtimeFiles() { + protected function updateNoOriginalCtimeFiles($file) { + if (!empty($file['original_ctime'])) { + return false; + } + + $cacheKey = $this->noOriginalCtimeFilesCacheKey; + $cacheData = Common::getCache($cacheKey); + if (empty($cacheData)) { + $cacheData = array(); + } + if (in_array($file['id'], $cacheData)) { + return false; + } + + array_push($cacheData, $file['id']); + + return Common::setCache($cacheKey, $cacheData); + } + + protected function saveNoOriginalCtimeFilesIntoFile() { + $cacheKey = $this->noOriginalCtimeFilesCacheKey; + $cacheData = Common::getCache($cacheKey); + if (empty($cacheData)) { + return false; + } + + return Common::saveCacheToFile($cacheKey, $cacheData); } public function actionTest() {