|
|
@ -9,8 +9,9 @@ require_once __DIR__ . '/../../../plugins/Common.php'; |
|
|
|
Class CommandController extends Controller { |
|
|
|
Class CommandController extends Controller { |
|
|
|
protected $logPrefix = '[MainBot]'; |
|
|
|
protected $logPrefix = '[MainBot]'; |
|
|
|
protected $scanedDirCacheKey = 'MainBotScanedDirs'; |
|
|
|
protected $scanedDirCacheKey = 'MainBotScanedDirs'; |
|
|
|
protected $dateIndexCacheKey = 'MainBotDateIndex'; |
|
|
|
protected $dateIndexCacheKey = 'MainBotDateIndex'; //索引数据的key单独缓存,缓存key为此{cacheKey}_keys |
|
|
|
protected $noOriginalCtimeFilesCacheKey = 'MainBotNoOriginalCtimeFiles'; |
|
|
|
protected $noOriginalCtimeFilesCacheKey = 'MainBotNoOriginalCtimeFiles'; |
|
|
|
|
|
|
|
protected $allFilesCacheKey = 'MainBotAllFiles'; |
|
|
|
|
|
|
|
|
|
|
|
public function actionIndex() { |
|
|
|
public function actionIndex() { |
|
|
|
$commands = <<<eof |
|
|
|
$commands = <<<eof |
|
|
@ -125,6 +126,8 @@ eof; |
|
|
|
$this->scanMediaFiles(); |
|
|
|
$this->scanMediaFiles(); |
|
|
|
$this->saveDateIndexIntoCacheFile(); |
|
|
|
$this->saveDateIndexIntoCacheFile(); |
|
|
|
$this->saveNoOriginalCtimeFilesIntoFile(); |
|
|
|
$this->saveNoOriginalCtimeFilesIntoFile(); |
|
|
|
|
|
|
|
//缓存所有文件id跟文件信息,便于根据id列表来渲染,并按id首字母分子目录存放,以支持大量文件的场景 |
|
|
|
|
|
|
|
$this->saveAllFilesIntoCacheFile(); |
|
|
|
|
|
|
|
|
|
|
|
//while (true) { |
|
|
|
//while (true) { |
|
|
|
//$time = date('Y-m-d H:i:s'); |
|
|
|
//$time = date('Y-m-d H:i:s'); |
|
|
@ -200,6 +203,8 @@ eof; |
|
|
|
$scanIndex ++; |
|
|
|
$scanIndex ++; |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($item['filename'])) { |
|
|
|
if (!empty($item['filename'])) { |
|
|
|
|
|
|
|
//保存所有文件到索引 |
|
|
|
|
|
|
|
$this->updateAllFilesCache($item); |
|
|
|
//更新年份、月份时间索引 |
|
|
|
//更新年份、月份时间索引 |
|
|
|
$this->updateDateIndex($item); |
|
|
|
$this->updateDateIndex($item); |
|
|
|
//更新没有拍摄时间的文件索引 |
|
|
|
//更新没有拍摄时间的文件索引 |
|
|
@ -292,7 +297,68 @@ eof; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Common::saveCacheToFile($cacheKey, $cacheData); |
|
|
|
$cacheDir = 'index'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//save index keys |
|
|
|
|
|
|
|
$indexKeys = []; |
|
|
|
|
|
|
|
foreach ($cacheData as $year => $item) { |
|
|
|
|
|
|
|
$indexKeys[$year] = array_keys($item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Common::saveCacheToFile("{$cacheKey}_keys", $indexKeys, $cacheDir); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Common::saveCacheToFile($cacheKey, $cacheData, $cacheDir); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function updateAllFilesCache($file) { |
|
|
|
|
|
|
|
$cacheKey = $this->allFilesCacheKey; |
|
|
|
|
|
|
|
$cacheData = Common::getCache($cacheKey); |
|
|
|
|
|
|
|
if (empty($cacheData)) { |
|
|
|
|
|
|
|
$cacheData = array(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$cacheData[$file['id']] = $file; |
|
|
|
|
|
|
|
return Common::setCache($cacheKey, $cacheData); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getFilesByFirstCharcter($files, $dirNum) { |
|
|
|
|
|
|
|
$byFirst = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($files as $id => $item) { |
|
|
|
|
|
|
|
$firstChar = substr($id, 0, 1); |
|
|
|
|
|
|
|
$ascNum = ord($firstChar); |
|
|
|
|
|
|
|
$index = $ascNum % $dirNum; |
|
|
|
|
|
|
|
if (empty($byFirst[$index])) { |
|
|
|
|
|
|
|
$byFirst[$index] = []; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$byFirst[$index][$id] = $item; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $byFirst; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function saveAllFilesIntoCacheFile() { |
|
|
|
|
|
|
|
$cacheKey = $this->allFilesCacheKey; |
|
|
|
|
|
|
|
$cacheData = Common::getCache($cacheKey); |
|
|
|
|
|
|
|
if (empty($cacheData)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$total = count($cacheData); |
|
|
|
|
|
|
|
$dirNum = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($total > 1000 && $total <= 10000) { |
|
|
|
|
|
|
|
$dirNum = 10; |
|
|
|
|
|
|
|
}else if ($total > 10000){ |
|
|
|
|
|
|
|
$dirNum = 100; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$filesByFirstChar = $this->getFilesByFirstCharcter($cacheData, $dirNum); |
|
|
|
|
|
|
|
$cacheDir = 'index'; |
|
|
|
|
|
|
|
for ($i=1;$i<=$dirNum;$i++) { |
|
|
|
|
|
|
|
Common::saveCacheToFile("{$cacheKey}_{$i}", $filesByFirstChar[$i-1], $cacheDir); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//汇总每个目录下图片、视频、音乐文件数量 |
|
|
|
//汇总每个目录下图片、视频、音乐文件数量 |
|
|
@ -336,7 +402,8 @@ eof; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Common::saveCacheToFile($cacheKey, $cacheData); |
|
|
|
$cacheDir = 'index'; |
|
|
|
|
|
|
|
return Common::saveCacheToFile($cacheKey, $cacheData, $cacheDir); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function actionTest() { |
|
|
|
public function actionTest() { |
|
|
|