I have a form with autocomplete feature as you type. The feature is slow. An average typing speed is faster than the autocomplete list. You can finish typing before the suggestion pops out. It uses jQuery to and makes an ajax call to a URL which calls a function within a controller that then runs all the list containing the typed string:
The network tab in the chrome developer tools only showed me how long the URL that gets called took and its about 700ms.
public function searchResponse(Request $request){
$query1 = $request->get('term','');
$c1=\DB::table('T_EMPLOYEE_SERVICE_AREAS');
if($request->type=='EmpService')
{
$c1->where('EmployeeService','LIKE','%'.$query1.'%')
->groupBy('EmployeeService')
->get();
}
$c1=$c1->get();
$data=array();
foreach ($c1 as $service) {
$data[]=array('EmployeeService'=>$service->EmployeeService);
}
if(count($data))
return $data;
else
return ['EmployeeService'=>''];
}
Aside from maybe optimizing the above query - how would I go about checking where the the most time is spent. I have added a link of the exact same autocomplete script I got from another forum http://www.expertphp.in/article/laravel-5-autocomplete-mutiple-fields-using-jquery-ajax-and-mysql