mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-25 12:09:09 +08:00
调整内容缓存时间
This commit is contained in:
parent
3e08ad8dcb
commit
3ae0d0df82
@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
|
||||||
* @license https://opensource.org/licenses/GPL-2.0
|
|
||||||
* @link https://www.koogua.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Caches;
|
|
||||||
|
|
||||||
use App\Models\Category as CategoryModel;
|
|
||||||
use App\Repos\Course as CourseRepo;
|
|
||||||
|
|
||||||
class CourseCategoryList extends Cache
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
|
||||||
|
|
||||||
public function getLifetime()
|
|
||||||
{
|
|
||||||
return $this->lifetime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getKey($id = null)
|
|
||||||
{
|
|
||||||
return "course_category_list:{$id}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getContent($id = null)
|
|
||||||
{
|
|
||||||
$courseRepo = new CourseRepo();
|
|
||||||
|
|
||||||
$categories = $courseRepo->findCategories($id);
|
|
||||||
|
|
||||||
if ($categories->count() == 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->handleContent($categories);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param CategoryModel[] $categories
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function handleContent($categories)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
foreach ($categories as $category) {
|
|
||||||
$result[] = [
|
|
||||||
'id' => $category->id,
|
|
||||||
'name' => $category->name,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
|
||||||
* @license https://opensource.org/licenses/GPL-2.0
|
|
||||||
* @link https://www.koogua.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Caches;
|
|
||||||
|
|
||||||
use App\Models\User as UserModel;
|
|
||||||
use App\Repos\Course as CourseRepo;
|
|
||||||
|
|
||||||
class CourseTeacherList extends Cache
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
|
||||||
|
|
||||||
public function getLifetime()
|
|
||||||
{
|
|
||||||
return $this->lifetime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getKey($id = null)
|
|
||||||
{
|
|
||||||
return "course_teacher_list:{$id}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getContent($id = null)
|
|
||||||
{
|
|
||||||
$courseRepo = new CourseRepo();
|
|
||||||
|
|
||||||
$users = $courseRepo->findTeachers($id);
|
|
||||||
|
|
||||||
if ($users->count() == 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->handleContent($users);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param UserModel[] $users
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function handleContent($users)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$result[] = [
|
|
||||||
'id' => $user->id,
|
|
||||||
'name' => $user->name,
|
|
||||||
'avatar' => $user->avatar,
|
|
||||||
'vip' => $user->vip,
|
|
||||||
'title' => $user->title,
|
|
||||||
'about' => $user->about,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -16,6 +16,8 @@ class FeaturedArticleList extends Cache
|
|||||||
|
|
||||||
protected $lifetime = 3600;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
|
protected $limit = 5;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
return $this->lifetime;
|
return $this->lifetime;
|
||||||
@ -28,9 +30,7 @@ class FeaturedArticleList extends Cache
|
|||||||
|
|
||||||
public function getContent($id = null)
|
public function getContent($id = null)
|
||||||
{
|
{
|
||||||
$limit = 8;
|
$articles = $this->findArticles($this->limit);
|
||||||
|
|
||||||
$articles = $this->findArticles($limit);
|
|
||||||
|
|
||||||
if ($articles->count() == 0) {
|
if ($articles->count() == 0) {
|
||||||
return [];
|
return [];
|
||||||
@ -67,7 +67,7 @@ class FeaturedArticleList extends Cache
|
|||||||
* @param int $limit
|
* @param int $limit
|
||||||
* @return ResultsetInterface|Resultset|ArticleModel[]
|
* @return ResultsetInterface|Resultset|ArticleModel[]
|
||||||
*/
|
*/
|
||||||
protected function findArticles($limit = 8)
|
protected function findArticles($limit = 5)
|
||||||
{
|
{
|
||||||
return ArticleModel::query()
|
return ArticleModel::query()
|
||||||
->where('featured = 1')
|
->where('featured = 1')
|
||||||
|
@ -16,6 +16,8 @@ class FeaturedCourseList extends Cache
|
|||||||
|
|
||||||
protected $lifetime = 3600;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
|
protected $limit = 5;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
return $this->lifetime;
|
return $this->lifetime;
|
||||||
@ -28,9 +30,7 @@ class FeaturedCourseList extends Cache
|
|||||||
|
|
||||||
public function getContent($id = null)
|
public function getContent($id = null)
|
||||||
{
|
{
|
||||||
$limit = 5;
|
$courses = $this->findCourses($this->limit);
|
||||||
|
|
||||||
$courses = $this->findCourses($limit);
|
|
||||||
|
|
||||||
if ($courses->count() == 0) {
|
if ($courses->count() == 0) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -16,6 +16,8 @@ class FeaturedQuestionList extends Cache
|
|||||||
|
|
||||||
protected $lifetime = 3600;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
|
protected $limit = 5;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
return $this->lifetime;
|
return $this->lifetime;
|
||||||
@ -28,9 +30,7 @@ class FeaturedQuestionList extends Cache
|
|||||||
|
|
||||||
public function getContent($id = null)
|
public function getContent($id = null)
|
||||||
{
|
{
|
||||||
$limit = 5;
|
$questions = $this->findQuestions($this->limit);
|
||||||
|
|
||||||
$questions = $this->findQuestions($limit);
|
|
||||||
|
|
||||||
if ($questions->count() == 0) {
|
if ($questions->count() == 0) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -15,7 +15,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class HelpList extends Cache
|
class HelpList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 365 * 86400;
|
protected $lifetime = 7 * 86400;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -14,13 +14,11 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class HotQuestionList extends Cache
|
class HotQuestionList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
$tomorrow = strtotime('tomorrow');
|
return $this->lifetime;
|
||||||
|
|
||||||
return $tomorrow - time();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getKey($id = null)
|
public function getKey($id = null)
|
||||||
|
@ -14,7 +14,7 @@ use App\Services\Logic\Article\ArticleList as ArticleListService;
|
|||||||
class IndexArticleList extends Cache
|
class IndexArticleList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 15 * 60;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexFeaturedCourseList extends Cache
|
class IndexFeaturedCourseList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexFreeCourseList extends Cache
|
class IndexFreeCourseList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexLiveList extends Cache
|
class IndexLiveList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexNewCourseList extends Cache
|
class IndexNewCourseList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ use App\Services\Logic\Question\QuestionList as QuestionListService;
|
|||||||
class IndexQuestionList extends Cache
|
class IndexQuestionList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 15 * 60;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexSimpleFeaturedCourseList extends Cache
|
class IndexSimpleFeaturedCourseList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexSimpleFreeCourseList extends Cache
|
class IndexSimpleFreeCourseList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexSimpleNewCourseList extends Cache
|
class IndexSimpleNewCourseList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexSimpleVipCourseList extends Cache
|
class IndexSimpleVipCourseList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexSlideList extends Cache
|
class IndexSlideList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 365 * 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class IndexVipCourseList extends Cache
|
class IndexVipCourseList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ class TaggedArticleList extends Cache
|
|||||||
|
|
||||||
protected $limit = 5;
|
protected $limit = 5;
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ class TaggedQuestionList extends Cache
|
|||||||
|
|
||||||
protected $limit = 5;
|
protected $limit = 5;
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class TopAnswererList extends Cache
|
class TopAnswererList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
|
|||||||
class TopAuthorList extends Cache
|
class TopAuthorList extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 86400;
|
protected $lifetime = 3600;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
|
||||||
* @license https://opensource.org/licenses/GPL-2.0
|
|
||||||
* @link https://www.koogua.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Services\Logic\Course;
|
|
||||||
|
|
||||||
use App\Caches\CourseTeacherList as CourseTeacherListCache;
|
|
||||||
use App\Services\Logic\CourseTrait;
|
|
||||||
use App\Services\Logic\Service as LogicService;
|
|
||||||
|
|
||||||
class TeacherList extends LogicService
|
|
||||||
{
|
|
||||||
|
|
||||||
use CourseTrait;
|
|
||||||
|
|
||||||
public function handle($id)
|
|
||||||
{
|
|
||||||
$course = $this->checkCourse($id);
|
|
||||||
|
|
||||||
$cache = new CourseTeacherListCache();
|
|
||||||
|
|
||||||
$result = $cache->get($course->id);
|
|
||||||
|
|
||||||
return $result ?: [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user