Browse Source

no original create time file index added

master
filesite 6 days ago
parent
commit
b94f45c302
  1. 43
      themes/beauty/controller/CommandController.php

43
themes/beauty/controller/CommandController.php

@ -10,6 +10,7 @@ Class CommandController extends Controller {
protected $logPrefix = '[MainBot]'; protected $logPrefix = '[MainBot]';
protected $scanedDirCacheKey = 'MainBotScanedDirs'; protected $scanedDirCacheKey = 'MainBotScanedDirs';
protected $dateIndexCacheKey = 'MainBotDateIndex'; protected $dateIndexCacheKey = 'MainBotDateIndex';
protected $noOriginalCtimeFilesCacheKey = 'MainBotNoOriginalCtimeFiles';
public function actionIndex() { public function actionIndex() {
$commands = <<<eof $commands = <<<eof
@ -123,6 +124,7 @@ eof;
$this->cleanScanCaches(); $this->cleanScanCaches();
$this->scanMediaFiles(); $this->scanMediaFiles();
$this->saveDateIndexIntoCacheFile(); $this->saveDateIndexIntoCacheFile();
$this->saveNoOriginalCtimeFilesIntoFile();
//while (true) { //while (true) {
//$time = date('Y-m-d H:i:s'); //$time = date('Y-m-d H:i:s');
@ -136,6 +138,7 @@ eof;
protected function cleanScanCaches() { protected function cleanScanCaches() {
Common::setCache($this->scanedDirCacheKey, array()); Common::setCache($this->scanedDirCacheKey, array());
Common::setCache($this->dateIndexCacheKey, array()); Common::setCache($this->dateIndexCacheKey, array());
Common::setCache($this->noOriginalCtimeFilesCacheKey, array());
} }
//扫描媒体文件:图片、视频、音乐 //扫描媒体文件:图片、视频、音乐
@ -192,9 +195,11 @@ eof;
$scanIndex ++; $scanIndex ++;
//更新年份、月份时间索引
if (!empty($item['filename'])) { 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, ...]}} * {"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']; $ctime = !empty($file['original_ctime']) ? $file['original_ctime'] : $file['fstat']['ctime'];
$cacheKey = $this->dateIndexCacheKey; $cacheKey = $this->dateIndexCacheKey;
@ -267,6 +272,10 @@ eof;
$cacheData[$year][$month] = array(); $cacheData[$year][$month] = array();
} }
if (in_array($file['id'], $cacheData[$year][$month])) {
return false;
}
array_push($cacheData[$year][$month], $file['id']); array_push($cacheData[$year][$month], $file['id']);
return Common::setCache($cacheKey, $cacheData); return Common::setCache($cacheKey, $cacheData);
@ -296,8 +305,34 @@ eof;
* 数据格式: * 数据格式:
* [id1, id2, ...] * [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() { public function actionTest() {

Loading…
Cancel
Save