|
|
@@ -181,13 +181,15 @@ class ArticleService extends BaseService
|
|
|
}
|
|
|
|
|
|
$limit = ConfigService::make()->getConfigByCode('index_article_num',3);
|
|
|
- $datas = ArticleCateModel::with(['articles'=>function($q) use($limit){
|
|
|
- $q->take($limit);
|
|
|
- }])->where(['type'=>$type,'status'=>1,'mark'=>1])
|
|
|
+ $datas = ArticleCateModel::with(['articles'])->where(['type'=>$type,'status'=>1,'mark'=>1])
|
|
|
->select(['id','name','sort','type'])
|
|
|
- ->get();
|
|
|
+ ->get()->keyBy('id');
|
|
|
$datas = $datas? $datas->toArray() : [];
|
|
|
if($datas){
|
|
|
+ foreach ($datas as &$item){
|
|
|
+ $item['articles'] = $item['articles']? array_slice($item['articles'],0,$limit) :[];
|
|
|
+ }
|
|
|
+ unset($item);
|
|
|
RedisService::set($cacheKey, $datas, rand(300,600));
|
|
|
}
|
|
|
|