performance issues
Hi , my widget in dashboard take more than 40 sec to update the data when I change the filter in chart, can I improve the performance?
6 Replies
please can anyone help me ?
Show some code so people can help you 😄
Is it the database that takes so long?
protected function getData(): array
{
$organizationId = $this->filters['organization'] ?? null;
$dateRange = $this->filters['date_range'] ?? 'today';
$userType = $this->filters['type'] ?? 'visit';
$period = match ($dateRange) {
'today' => 'day',
'week' => 'week',
'month' => 'month',
default => 'day',
};
if ($userType === 'old') {
$url = env('ORGANIZATION_URL') . '/api/user-count';
$response = Http::get($url, [
'organization_id' => $organizationId,
'period' => $period,
]);
$responseData = $response->successful() ? $response->json() : [
'period' => $period,
'data' => [],
];
$data = $responseData['data'] ?? [];
}
else {
$query = \App\Models\User::query();
if ($organizationId) {
$query->where('organization', $organizationId);
}
switch ($period) {
}
return [
'labels' => array_keys($chartData),
'datasets' => [
[
'label' => ucfirst($userType) . ' users',
'data' => array_values($chartData),
], ], ]; } this is my function
], ], ]; } this is my function
Please format your code properly. See #✅┊rules
How long is your
Http request taking?!
it takes only
1.83 s