mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 20:06:09 +08:00
优化相关文章和问题
This commit is contained in:
parent
3ae0d0df82
commit
7a8d8ba342
@ -13,7 +13,7 @@ use App\Repos\Article as ArticleRepo;
|
||||
class TaggedArticleList extends Cache
|
||||
{
|
||||
|
||||
protected $limit = 5;
|
||||
protected $limit = 15;
|
||||
|
||||
protected $lifetime = 3600;
|
||||
|
||||
|
@ -13,7 +13,7 @@ use App\Repos\Question as QuestionRepo;
|
||||
class TaggedQuestionList extends Cache
|
||||
{
|
||||
|
||||
protected $limit = 5;
|
||||
protected $limit = 15;
|
||||
|
||||
protected $lifetime = 3600;
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
<style>
|
||||
html {
|
||||
height: 95%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
@ -72,7 +72,7 @@
|
||||
</script>
|
||||
|
||||
<script>
|
||||
jquery('body').buoyant({
|
||||
$('body').buoyant({
|
||||
elementClass: 'circles',
|
||||
numberOfItems: 20,
|
||||
minRadius: 5,
|
||||
|
@ -18,21 +18,33 @@ class RelatedArticleList extends LogicService
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$limit = $this->request->getQuery('limit', 'int', 5);
|
||||
|
||||
$article = $this->checkArticle($id);
|
||||
|
||||
if (empty($article->tags)) return [];
|
||||
|
||||
$tagIds = kg_array_column($article->tags, 'id');
|
||||
|
||||
$randKey = array_rand($tagIds);
|
||||
|
||||
$tagId = $tagIds[$randKey];
|
||||
$tagId = kg_array_rand($tagIds);
|
||||
|
||||
$cache = new TaggedArticleListCache();
|
||||
|
||||
$result = $cache->get($tagId);
|
||||
$articles = $cache->get($tagId);
|
||||
|
||||
return $result ?: [];
|
||||
if (empty($articles)) return [];
|
||||
|
||||
foreach ($articles as $key => $article) {
|
||||
if ($article['id'] == $id) {
|
||||
unset($articles[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit < count($articles)) {
|
||||
$articles = array_slice($articles, $limit);
|
||||
}
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,21 +18,33 @@ class RelatedQuestionList extends LogicService
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$limit = $this->request->getQuery('limit', 'int', 5);
|
||||
|
||||
$question = $this->checkQuestion($id);
|
||||
|
||||
if (empty($question->tags)) return [];
|
||||
|
||||
$tagIds = kg_array_column($question->tags, 'id');
|
||||
|
||||
$randKey = array_rand($tagIds);
|
||||
|
||||
$tagId = $tagIds[$randKey];
|
||||
$tagId = kg_array_rand($tagIds);
|
||||
|
||||
$cache = new TaggedQuestionListCache();
|
||||
|
||||
$result = $cache->get($tagId);
|
||||
$questions = $cache->get($tagId);
|
||||
|
||||
return $result ?: [];
|
||||
if (empty($questions)) return [];
|
||||
|
||||
foreach ($questions as $key => $question) {
|
||||
if ($question['id'] == $id) {
|
||||
unset($questions[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit < count($questions)) {
|
||||
$questions = array_slice($questions, $limit);
|
||||
}
|
||||
|
||||
return $questions;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user