Skip to content

Commit 0b51cac

Browse files
ismoilovdevmlclaude
andcommitted
perf: Optimize Active Jobs polling and caching for faster updates
Active Jobs Performance Improvements: - Add 30-second cache to getPipelineJobs to reduce API calls - Reduce getAllActivePipelines cache from 2 minutes to 30 seconds - Use direct API calls in getAllActivePipelines to bypass stale cache - Increase running pipelines limit from 5 to 20 for better visibility - Increase active jobs display limit from 10 to 20 This fixes the issue where short-running jobs (20-30 seconds) were missed due to slow polling and long cache times. Jobs now appear within 30 seconds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ef5f4e7 commit 0b51cac

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

src/components/Overview.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export default function Overview() {
7676
.slice(0, 50); // Keep more pipelines for accurate counting
7777
setRecentPipelines(recent);
7878

79-
// Load active jobs from running pipelines
80-
const runningPipelines = pipelines.slice(0, 5);
79+
// Load active jobs from running pipelines (increased to 20 for better visibility)
80+
const runningPipelines = pipelines.slice(0, 20);
8181
const jobsPromises = runningPipelines.map(pipeline =>
8282
api.getPipelineJobs(pipeline.project_id, pipeline.id).catch(() => [])
8383
);
@@ -88,7 +88,7 @@ export default function Overview() {
8888
.flat()
8989
.filter(job => job.status === 'running' || job.status === 'pending')
9090
.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())
91-
.slice(0, 10);
91+
.slice(0, 20); // Show up to 20 active jobs
9292

9393
// Enrich jobs with project data from store
9494
const enrichedJobs = jobs.map(job => {

src/lib/gitlab-api.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,30 @@ class GitLabAPI {
426426
}
427427

428428
async getAllActivePipelines(): Promise<Pipeline[]> {
429-
// Limit to 20 most active projects to reduce memory usage
430-
const projects = await this.getProjects(1, 20);
431-
const pipelinePromises = projects.map(project =>
432-
this.getPipelines(project.id, 1, 5).catch(() => [])
429+
return cachedFetch(
430+
'gitlab:active-pipelines',
431+
async () => {
432+
// Limit to 20 most active projects to reduce memory usage
433+
const projects = await this.getProjects(1, 20);
434+
const pipelinePromises = projects.map(project =>
435+
// Direct API call without cache for fresh data
436+
this.api.get(`/projects/${project.id}/pipelines`, {
437+
params: {
438+
per_page: 10,
439+
page: 1,
440+
order_by: 'updated_at',
441+
},
442+
}).then(res => res.data as Pipeline[]).catch(() => [])
443+
);
444+
const allPipelines = await Promise.all(pipelinePromises);
445+
return allPipelines
446+
.flat()
447+
.filter(p => ['running', 'pending', 'created'].includes(p.status))
448+
.sort((a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime())
449+
.slice(0, 50); // Limit to 50 active pipelines max
450+
},
451+
CacheTTL.SHORT // 30 seconds cache for active pipelines - fast updates
433452
);
434-
const allPipelines = await Promise.all(pipelinePromises);
435-
return allPipelines
436-
.flat()
437-
.filter(p => ['running', 'pending', 'created'].includes(p.status))
438-
.sort((a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime())
439-
.slice(0, 50); // Limit to 50 active pipelines max
440453
}
441454

442455
async getPipeline(projectId: number, pipelineId: number): Promise<Pipeline> {
@@ -456,8 +469,14 @@ class GitLabAPI {
456469

457470
// Jobs
458471
async getPipelineJobs(projectId: number, pipelineId: number): Promise<Job[]> {
459-
const response = await this.api.get(`/projects/${projectId}/pipelines/${pipelineId}/jobs`);
460-
return response.data;
472+
return cachedFetch(
473+
`gitlab:jobs:${projectId}:${pipelineId}`,
474+
async () => {
475+
const response = await this.api.get(`/projects/${projectId}/pipelines/${pipelineId}/jobs`);
476+
return response.data;
477+
},
478+
CacheTTL.SHORT // 30 seconds cache for jobs to catch running jobs quickly
479+
);
461480
}
462481

463482
async getJob(projectId: number, jobId: number): Promise<Job> {

0 commit comments

Comments
 (0)