作者 刘朕
1 个管道 的构建 通过 耗费 2 秒

我的界面上接口优化

@@ -233,13 +233,22 @@ class Mycenter extends Api @@ -233,13 +233,22 @@ class Mycenter extends Api
233 ->where('user_id',$userid) 233 ->where('user_id',$userid)
234 ->where('type',1) 234 ->where('type',1)
235 ->group('idea_type_id') 235 ->group('idea_type_id')
  236 + ->orderRaw('count(idea_type_id) desc')
236 ->orderRaw('createtime desc') 237 ->orderRaw('createtime desc')
237 ->field('idea_type_id,count(idea_type_id)') 238 ->field('idea_type_id,count(idea_type_id)')
238 ->limit(10) 239 ->limit(10)
239 ->column('idea_type_id'); 240 ->column('idea_type_id');
240 // $ideaUserRecord = $ideaUserRecord->toArray(); 241 // $ideaUserRecord = $ideaUserRecord->toArray();
241 if ($ideaUserRecord){ 242 if ($ideaUserRecord){
242 - $ideaType = IdeaType::whereIn('id',$ideaUserRecord)->select(); 243 + $ideaType = [];
  244 + foreach ($ideaUserRecord as $k=>$v) {
  245 + if($k < 3) {
  246 + $ideaType[] = IdeaType::where('id',$v)->find();
  247 + } else {
  248 + break;
  249 + }
  250 + }
  251 +// $ideaType = IdeaType::whereIn('id',$ideaUserRecord)->select();
243 $string = ''; 252 $string = '';
244 foreach ($ideaType as $key => $value){ 253 foreach ($ideaType as $key => $value){
245 $string.= $value['name'].','; 254 $string.= $value['name'].',';