feat: implement dashboard pagination
This commit is contained in:
@@ -42,12 +42,18 @@ if ($method === 'POST' && $uri === '/api/queue') {
|
||||
exit;
|
||||
}
|
||||
|
||||
// API: Jobs History
|
||||
// API: Jobs History (Paginated)
|
||||
if ($method === 'GET' && $uri === '/api/jobs') {
|
||||
// Get last 50 jobs
|
||||
$ids = $redis->lrange('job_history', 0, 49);
|
||||
$jobs = [];
|
||||
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
|
||||
$limit = isset($_GET['limit']) ? max(1, min(100, (int)$_GET['limit'])) : 20;
|
||||
|
||||
$start = ($page - 1) * $limit;
|
||||
$end = $start + $limit - 1;
|
||||
|
||||
$total = $redis->llen('job_history');
|
||||
$ids = $redis->lrange('job_history', $start, $end);
|
||||
|
||||
$jobs = [];
|
||||
foreach ($ids as $id) {
|
||||
$job = $redis->hgetall("job:$id");
|
||||
if ($job) {
|
||||
@@ -55,7 +61,13 @@ if ($method === 'GET' && $uri === '/api/jobs') {
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($jobs);
|
||||
echo json_encode([
|
||||
'jobs' => $jobs,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'total_pages' => ceil($total / $limit)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user