follows the full flow of the log
Jul 3, 2023
7
Level 1
Laravel API slow query
Guys, how are you?
I have a problem with an API I made for a client. This API consists of querying an endpoint every 2s to see if there are notes. Whenever a query is performed, it needs to be completed for another to be started, that is, they do not accumulate.
route:
Route::get('notes/{tenant}', [InvoiceController::class, 'index']);
controller:
public function index(string $tenant)
{
$invoice = Invoice::where([
['status', 'process'], ['tenant', $tenant]
])->first();
if ($invoice) {
$data['data'] = new InvoiceResource($invoice);
} else {
$data['data'] = [];
}
return response()->json($data);
}
The problem is that until today the client has not issued any notes, that is, the bank is empty, but sometimes this query takes up to 21s.
image that shows more details of the log: https://imgur.com/a/A1AGjrh
Please or to participate in this conversation.