Skip to content

Commit 0ed240a

Browse files
committed
perf: implement redis caching on ticket filters to reduce database load
1 parent 6568aa4 commit 0ed240a

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

app/Http/Controllers/Agent/helpdesk/Filter/FilterController.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use App\User;
1818
//classes
1919
use Auth;
20+
use Cache;
2021
use DB;
2122
use Illuminate\Http\Request;
2223

@@ -58,27 +59,32 @@ public function __construct(Request $req)
5859
*/
5960
public function getFilter(Request $request)
6061
{
61-
$table = $this->table();
62-
if ($request->has('segment')) {
63-
$segment = $this->request->input('segment');
64-
$table = $this->formatUserTickets($segment);
65-
} else {
66-
if ($request->has('api') && $request->get('api') == '1') {
67-
$inputs = [];
68-
foreach ($request->all() as $key => $value) {
69-
if ($key != 'api' && $key != 'token' && $key != 'page' && $key
70-
!= 'sort-by' && $key != 'order' && $key != 'records_per_page') {
71-
$inputs[$key] = explode(',', $value); //
72-
}
73-
}
62+
$cacheKey = 'agent_tickets_page_'.Auth::id().'_'.md5($request->getRequestUri());
7463

75-
return $table = $this->checkRequestIsCorrect($table, $inputs);
64+
$table = Cache::remember($cacheKey, 300, function () use ($request) {
65+
$table = $this->table();
66+
if ($request->has('segment')) {
67+
$segment = $this->request->input('segment');
68+
$table = $this->formatUserTickets($segment);
7669
} else {
77-
$inputs = json_decode(htmlspecialchars_decode($request->get('options')));
78-
// dd($inputs);
79-
$table = $this->checkRequestIsCorrect($table, (array) $inputs);
70+
if ($request->has('api') && $request->get('api') == '1') {
71+
$inputs = [];
72+
foreach ($request->all() as $key => $value) {
73+
if ($key != 'api' && $key != 'token' && $key != 'page' && $key
74+
!= 'sort-by' && $key != 'order' && $key != 'records_per_page') {
75+
$inputs[$key] = explode(',', $value); //
76+
}
77+
}
78+
79+
$table = $this->checkRequestIsCorrect($table, $inputs);
80+
} else {
81+
$inputs = json_decode(htmlspecialchars_decode($request->get('options')));
82+
$table = $this->checkRequestIsCorrect($table, (array) $inputs);
83+
}
8084
}
81-
}
85+
86+
return $table;
87+
});
8288

8389
return \Ttable::genreateTableJson($table);
8490
}

0 commit comments

Comments
 (0)