fix chapter page

This commit is contained in:
Default
2025-04-03 17:21:55 +08:00
parent 199ce7f653
commit e65887f52e
2 changed files with 94 additions and 1 deletions

View File

@@ -36,6 +36,75 @@ class ChapterModel extends MongoModel
],
];
/**
* Undocumented function
*
* @param string $strKey
* @param array $arrFilter
* @param integer $intPage
* @param integer $intLimit
* @param integer $intLifeTime
* @param array $arrSort
* @return array
*/
public function getCommonNovelPageOnCache(
string $strKey,
array $arrFilter,
int $intPage = 1,
int $intLimit = 20,
int $intLifeTime = 24 * 3600,
array $arrSort = ['c_sort_num' => 1]
): array {
try {
$arrResult = Cache::get($strKey);
// if (empty($arrResult)) {
if (true) {
$arrOptions = self::$arrChapterOptions;
$arrOptions = array_merge($arrOptions, [
'sort' => $arrSort,
// 'limit' => $intCount * 3,
'skip' => ($intPage - 1) * $intLimit,
'limit' => $intLimit,
]);
$Cursor = $this->getCol()->find($arrFilter, $arrOptions);
$intTotal = $this->getCol()->countDocuments($arrFilter);
$arrResult = iterator_to_array($Cursor);
if (!empty($arrResult)) {
foreach($arrResult as &$arrChapter){
applyToKeys($arrChapter, ['created_at', 'updated_at'], 'formatMongoDate');
}
}
$arrResult = [
'data' => $arrResult,
'total' => $intTotal,
'page' => $intPage,
'limit' => $intLimit,
'pages' => ceil($intTotal / $intLimit)
];
if (!empty($arrResult)) {
Cache::set($strKey, $arrResult, $intLifeTime);
}
}
return $arrResult;
} catch (\Exception $e) {
return [];
}
}
/**
* Undocumented function
*