Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed issue where parenthesis in query params were not being encoded, resulting in a poor experience when embedding links in Markdown. [#674](https://github.com/sourcebot-dev/sourcebot/pull/674)
- Gitlab clone respects host protocol setting in environment variable. [#676](https://github.com/sourcebot-dev/sourcebot/pull/676)
- Fixed performance issues with `/repos` page. [#677](https://github.com/sourcebot-dev/sourcebot/pull/677)

## [4.10.3] - 2025-12-12

Expand Down
25 changes: 25 additions & 0 deletions packages/backend/src/repoIndexManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ export class RepoIndexManager {
},
data: {
status: RepoIndexingJobStatus.IN_PROGRESS,
repo: {
update: {
latestIndexingJobStatus: RepoIndexingJobStatus.IN_PROGRESS,
}
}
},
select: {
type: true,
Expand Down Expand Up @@ -462,6 +467,11 @@ export class RepoIndexManager {
data: {
status: RepoIndexingJobStatus.COMPLETED,
completedAt: new Date(),
repo: {
update: {
latestIndexingJobStatus: RepoIndexingJobStatus.COMPLETED,
}
}
},
include: {
repo: true,
Expand Down Expand Up @@ -522,6 +532,11 @@ export class RepoIndexManager {
status: RepoIndexingJobStatus.FAILED,
completedAt: new Date(),
errorMessage: job.failedReason,
repo: {
update: {
latestIndexingJobStatus: RepoIndexingJobStatus.FAILED,
}
}
},
select: { repo: true }
});
Expand Down Expand Up @@ -550,6 +565,11 @@ export class RepoIndexManager {
status: RepoIndexingJobStatus.FAILED,
completedAt: new Date(),
errorMessage: 'Job stalled',
repo: {
update: {
latestIndexingJobStatus: RepoIndexingJobStatus.FAILED,
}
}
},
select: { repo: true, type: true }
});
Expand All @@ -572,6 +592,11 @@ export class RepoIndexManager {
status: RepoIndexingJobStatus.FAILED,
completedAt: new Date(),
errorMessage: 'Job timed out',
repo: {
update: {
latestIndexingJobStatus: RepoIndexingJobStatus.FAILED,
}
}
},
select: { repo: true }
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Repo" ADD COLUMN "latestIndexingJobStatus" "RepoIndexingJobStatus";
1 change: 1 addition & 0 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ model Repo {
jobs RepoIndexingJob[]
indexedAt DateTime? /// When the repo was last indexed successfully.
indexedCommitHash String? /// The commit hash of the last indexed commit (on HEAD).
latestIndexingJobStatus RepoIndexingJobStatus? /// The status of the latest indexing job.
external_id String /// The id of the repo in the external service
external_codeHostType CodeHostType /// The type of the external service (e.g., github, gitlab, etc.)
Expand Down
72 changes: 52 additions & 20 deletions packages/db/tools/scripts/inject-repo-data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Script } from "../scriptRunner";
import { PrismaClient } from "../../dist";

const NUM_REPOS = 100000;
const NUM_REPOS = 1000;
const NUM_INDEXING_JOBS_PER_REPO = 10000;
const NUM_PERMISSION_JOBS_PER_REPO = 10000;

export const injectRepoData: Script = {
run: async (prisma: PrismaClient) => {
Expand Down Expand Up @@ -32,30 +34,60 @@ export const injectRepoData: Script = {
});


console.log(`Creating ${NUM_REPOS} repos...`);
console.log(`Creating ${NUM_REPOS} repos...`);

for (let i = 0; i < NUM_REPOS; i++) {
await prisma.repo.create({
data: {
name: `test-repo-${i}`,
isFork: false,
isArchived: false,
metadata: {},
cloneUrl: `https://github.com/test-org/test-repo-${i}`,
webUrl: `https://github.com/test-org/test-repo-${i}`,
orgId,
external_id: `test-repo-${i}`,
external_codeHostType: 'github',
external_codeHostUrl: 'https://github.com',
connections: {
create: {
connectionId: connection.id,
}
const statuses = ['PENDING', 'IN_PROGRESS', 'COMPLETED', 'FAILED'] as const;
const indexingJobTypes = ['INDEX', 'CLEANUP'] as const;

for (let i = 0; i < NUM_REPOS; i++) {
const repo = await prisma.repo.create({
data: {
name: `test-repo-${i}`,
isFork: false,
isArchived: false,
metadata: {},
cloneUrl: `https://github.com/test-org/test-repo-${i}`,
webUrl: `https://github.com/test-org/test-repo-${i}`,
orgId,
external_id: `test-repo-${i}`,
external_codeHostType: 'github',
external_codeHostUrl: 'https://github.com',
connections: {
create: {
connectionId: connection.id,
}
}
}
});

for (let j = 0; j < NUM_PERMISSION_JOBS_PER_REPO; j++) {
const status = statuses[Math.floor(Math.random() * statuses.length)];
await prisma.repoPermissionSyncJob.create({
data: {
repoId: repo.id,
status,
completedAt: status === 'COMPLETED' || status === 'FAILED' ? new Date() : null,
errorMessage: status === 'FAILED' ? 'Mock error message' : null
}
});
}

console.log(`Created ${NUM_REPOS} repos.`);
for (let j = 0; j < NUM_INDEXING_JOBS_PER_REPO; j++) {
const status = statuses[Math.floor(Math.random() * statuses.length)];
const type = indexingJobTypes[Math.floor(Math.random() * indexingJobTypes.length)];
await prisma.repoIndexingJob.create({
data: {
repoId: repo.id,
type,
status,
completedAt: status === 'COMPLETED' || status === 'FAILED' ? new Date() : null,
errorMessage: status === 'FAILED' ? 'Mock indexing error' : null,
metadata: {}
}
});
}
}

console.log(`Created ${NUM_REPOS} repos with associated jobs.`);
}
};
Loading