0

I am working on a dashboard graphs on a laravel project I have may combo graphs in the dashboard so, i need to have a verygood performance

my problem is the number of statements that i should run to get the graph data from database

for example: i need to get the number of leads per user group by lead source in each month, so i have to run my mysql statements (no of users * number of lead sources * 12) times, this way is very slow and hard

$cash=array();
$users=DB::table('users')->where('deleted','0')->get();
foreach($users as $user){
    for($f=1;$f<=12 ;$f++){
        if($f<10) $ee='0'.$f; else $ee=$f;
        $amount=DB::table('installments')->where('deleted','0')->where('owner',$user->id)->where('status','23')->where(DB::raw('DATE_FORMAT(date, "%Y-%m") '),date("Y-".$ee))->sum("amount");

        array_push($cash, $amount);
    }
}

i need another way which allow me to get the combo bar charts from database in high performance

Hala Atef
  • 21
  • 6
  • can you share some code – ManojKiran A Jun 16 '19 at 12:39
  • possible duplicate? https://stackoverflow.com/questions/1775168/multiple-select-statements-in-single-query – user3553260 Jun 16 '19 at 12:55
  • For fetching relationship data, user `->with('relationship')` on the query to fetch relationship details in advance instead of 1 by 1, this could save 20+ queries depending on how many you fetch. And after you fetched the results, maybe cache it for 5-10mins? At least 1min though. My 2cents :> – emotality Jun 16 '19 at 13:41

0 Answers0