Skip to content

Commit 81c4190

Browse files
simplicity: remove much of the web changes
1 parent 1232e4b commit 81c4190

19 files changed

Lines changed: 1069 additions & 674 deletions

File tree

packages/backend/src/jobManager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export class BullMQJobManager implements JobManager {
123123
`${LOG_TAG}:${spec.name}:job:${job.id ?? 'unknown'}`,
124124
);
125125
const lifecycleContext = this.jobLifecycleContext<TName>(job);
126-
jobLogger.debug(`Started workload "${spec.name}"`);
127126

128127
try {
129128
await workload.onStarted?.(lifecycleContext);
@@ -134,7 +133,6 @@ export class BullMQJobManager implements JobManager {
134133
updateProgress: (progress) => job.updateProgress(progress),
135134
trigger: (target, data) => this.trigger(target, data),
136135
});
137-
jobLogger.debug(`Completed workload "${spec.name}"`);
138136
return result;
139137
} catch (error) {
140138
jobLogger.error(`Workload "${spec.name}" attempt failed`, error);

packages/db/prisma/migrations/20260728190236_remove_connection_sync_job_rows/migration.sql

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/db/prisma/migrations/20260728231844_remove_repo_index_job_rows/migration.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/db/prisma/schema.prisma

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ datasource db {
1010
url = env("DATABASE_URL")
1111
}
1212

13+
enum ConnectionSyncStatus {
14+
SYNC_NEEDED
15+
IN_SYNC_QUEUE
16+
SYNCING
17+
SYNCED
18+
SYNCED_WITH_WARNINGS
19+
FAILED
20+
}
21+
1322
enum ChatVisibility {
1423
PRIVATE
1524
PUBLIC
@@ -65,10 +74,10 @@ model Repo {
6574
permissionSyncJobs RepoPermissionSyncJob[]
6675
permissionSyncedAt DateTime? /// When the permissions were last synced successfully.
6776
77+
jobs RepoIndexingJob[]
6878
indexedAt DateTime? /// When the repo was last indexed successfully.
69-
latestIndexingJobId String?
70-
7179
indexedCommitHash String? /// The commit hash of the last indexed commit (on HEAD).
80+
latestIndexingJobStatus RepoIndexingJobStatus? /// The status of the latest indexing job.
7281
pushedAt DateTime? /// The timestamp of the most recent commit across all branches.
7382
7483
external_id String /// The id of the repo in the external service
@@ -86,6 +95,35 @@ model Repo {
8695
@@index([indexedAt])
8796
}
8897

98+
enum RepoIndexingJobStatus {
99+
PENDING
100+
IN_PROGRESS
101+
COMPLETED
102+
FAILED
103+
}
104+
105+
enum RepoIndexingJobType {
106+
INDEX
107+
CLEANUP
108+
}
109+
110+
model RepoIndexingJob {
111+
id String @id @default(cuid())
112+
type RepoIndexingJobType
113+
status RepoIndexingJobStatus @default(PENDING)
114+
createdAt DateTime @default(now())
115+
updatedAt DateTime @updatedAt
116+
completedAt DateTime?
117+
metadata Json? /// For schema see repoIndexingJobMetadataSchema in packages/shared/src/types.ts
118+
119+
errorMessage String?
120+
121+
repo Repo @relation(fields: [repoId], references: [id], onDelete: Cascade)
122+
repoId Int
123+
124+
@@index([repoId, type, status])
125+
}
126+
89127
enum RepoPermissionSyncJobStatus {
90128
PENDING
91129
IN_PROGRESS
@@ -143,9 +181,9 @@ model Connection {
143181
// The type of connection (e.g., github, gitlab, etc.)
144182
connectionType ConnectionType
145183
184+
syncJobs ConnectionSyncJob[]
146185
/// When the connection was last synced successfully.
147186
syncedAt DateTime?
148-
latestSyncJobId String?
149187
150188
/// Controls whether repository permissions are enforced for this connection.
151189
/// When `PERMISSION_SYNC_ENABLED` is false, this setting has no effect.
@@ -170,6 +208,27 @@ model Connection {
170208
@@unique([name, orgId])
171209
}
172210

211+
enum ConnectionSyncJobStatus {
212+
PENDING
213+
IN_PROGRESS
214+
COMPLETED
215+
FAILED
216+
}
217+
218+
model ConnectionSyncJob {
219+
id String @id @default(cuid())
220+
status ConnectionSyncJobStatus @default(PENDING)
221+
createdAt DateTime @default(now())
222+
updatedAt DateTime @updatedAt
223+
completedAt DateTime?
224+
225+
warningMessages String[]
226+
errorMessage String?
227+
228+
connection Connection @relation(fields: [connectionId], references: [id], onDelete: Cascade)
229+
connectionId Int
230+
}
231+
173232
model RepoToConnection {
174233
addedAt DateTime @default(now())
175234

packages/db/tools/scripts/inject-repo-data.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Script } from "../scriptRunner";
22
import { PrismaClient } from "../../dist";
33

44
const NUM_REPOS = 1000;
5+
const NUM_INDEXING_JOBS_PER_REPO = 10000;
56
const NUM_PERMISSION_JOBS_PER_REPO = 10000;
67

78
export const injectRepoData: Script = {
@@ -36,6 +37,8 @@ export const injectRepoData: Script = {
3637
console.log(`Creating ${NUM_REPOS} repos...`);
3738

3839
const statuses = ['PENDING', 'IN_PROGRESS', 'COMPLETED', 'FAILED'] as const;
40+
const indexingJobTypes = ['INDEX', 'CLEANUP'] as const;
41+
3942
for (let i = 0; i < NUM_REPOS; i++) {
4043
const repo = await prisma.repo.create({
4144
data: {
@@ -68,8 +71,23 @@ export const injectRepoData: Script = {
6871
}
6972
});
7073
}
74+
75+
for (let j = 0; j < NUM_INDEXING_JOBS_PER_REPO; j++) {
76+
const status = statuses[Math.floor(Math.random() * statuses.length)];
77+
const type = indexingJobTypes[Math.floor(Math.random() * indexingJobTypes.length)];
78+
await prisma.repoIndexingJob.create({
79+
data: {
80+
repoId: repo.id,
81+
type,
82+
status,
83+
completedAt: status === 'COMPLETED' || status === 'FAILED' ? new Date() : null,
84+
errorMessage: status === 'FAILED' ? 'Mock indexing error' : null,
85+
metadata: {}
86+
}
87+
});
88+
}
7189
}
7290

73-
console.log(`Created ${NUM_REPOS} repos with associated permission jobs.`);
91+
console.log(`Created ${NUM_REPOS} repos with associated jobs.`);
7492
}
75-
};
93+
};

packages/shared/src/queue.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,6 @@ export const CONNECTION_QUEUE: QueueSpec<'connection'> = {
2626
keep: { completed: 50, failed: 50 },
2727
keepLogs: DEFAULT_JOB_LOGS_MAX_ENTRIES,
2828
},
29-
onEnqueued: async ({
30-
prisma,
31-
data: { connectionId },
32-
jobId
33-
}) => {
34-
await prisma.connection.update({
35-
where: {
36-
id: connectionId
37-
},
38-
data: {
39-
latestSyncJobId: jobId
40-
}
41-
});
42-
},
4329
dedupKey: (data) => `connection:${data.connectionId}`,
4430
}
4531

@@ -62,20 +48,6 @@ export const REPO_INDEX_QUEUE: QueueSpec<'repo-index'> = {
6248
keep: { completed: 50, failed: 50 },
6349
keepLogs: DEFAULT_JOB_LOGS_MAX_ENTRIES,
6450
},
65-
onEnqueued: async ({
66-
prisma,
67-
data: { repoId },
68-
jobId,
69-
}) => {
70-
await prisma.repo.update({
71-
where: {
72-
id: repoId,
73-
},
74-
data: {
75-
latestIndexingJobId: jobId,
76-
},
77-
});
78-
},
7951
dedupKey: (data) => `repo:${data.repoId}`,
8052
};
8153

packages/web/src/actions.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createAudit } from "@/ee/features/audit/audit";
44
import { ErrorCode } from "@/lib/errorCodes";
55
import { notFound, ServiceError } from "@/lib/serviceError";
66
import { sew } from "@/middleware/sew";
7-
import { OrgRole, Prisma, RepoIndexingJobStatus, RepoIndexingJobType } from "@sourcebot/db";
7+
import { ConnectionSyncJobStatus, OrgRole, Prisma, RepoIndexingJobStatus, RepoIndexingJobType } from "@sourcebot/db";
88
import { GiteaConnectionConfig } from "@sourcebot/schemas/v3/gitea.type";
99
import { GithubConnectionConfig } from "@sourcebot/schemas/v3/github.type";
1010
import { GitlabConnectionConfig } from "@sourcebot/schemas/v3/gitlab.type";
@@ -274,6 +274,42 @@ export const getReposStats = async () => sew(() =>
274274
})
275275
)
276276

277+
export const getConnectionStats = async () => sew(() =>
278+
withAuth(async ({ org, prisma }) => {
279+
const [
280+
numberOfConnections,
281+
numberOfConnectionsWithFirstTimeSyncJobsInProgress,
282+
] = await Promise.all([
283+
prisma.connection.count({
284+
where: {
285+
orgId: org.id,
286+
}
287+
}),
288+
prisma.connection.count({
289+
where: {
290+
orgId: org.id,
291+
syncedAt: null,
292+
syncJobs: {
293+
some: {
294+
status: {
295+
in: [
296+
ConnectionSyncJobStatus.PENDING,
297+
ConnectionSyncJobStatus.IN_PROGRESS,
298+
]
299+
}
300+
}
301+
}
302+
}
303+
})
304+
]);
305+
306+
return {
307+
numberOfConnections,
308+
numberOfConnectionsWithFirstTimeSyncJobsInProgress,
309+
};
310+
})
311+
);
312+
277313
export const getRepoInfoByName = async (repoName: string) => sew(() =>
278314
withOptionalAuth(async ({ org, prisma }) => {
279315
// @note: repo names are represented by their remote url

packages/web/src/app/(app)/@sidebar/components/defaultSidebar/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { cookies } from "next/headers";
22
import { auth } from "@/auth";
33
import { HOME_VIEW_COOKIE_NAME } from "@/lib/constants";
44
import { HomeView } from "@/hooks/useHomeView";
5+
import { getConnectionStats } from "@/actions";
56
import { getOrgAccountRequests } from "@/features/membership/actions";
67
import { isServiceError } from "@/lib/utils";
78
import { ServiceErrorException } from "@/lib/serviceError";
@@ -45,9 +46,11 @@ export async function DefaultSidebar() {
4546
if (!isOwner) {
4647
return false;
4748
}
49+
const connectionStats = await getConnectionStats();
4850
const joinRequests = await getOrgAccountRequests();
51+
const hasConnectionNotification = !isServiceError(connectionStats) && connectionStats.numberOfConnectionsWithFirstTimeSyncJobsInProgress > 0;
4952
const hasJoinRequestNotification = !isServiceError(joinRequests) && joinRequests.length > 0;
50-
return hasJoinRequestNotification;
53+
return hasConnectionNotification || hasJoinRequestNotification;
5154
})();
5255

5356
return (

packages/web/src/app/(app)/chat/chatLandingPage.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getRepos, getSearchContexts } from "@/actions";
1+
import { getRepos, getReposStats, getSearchContexts } from "@/actions";
22
import { SourcebotLogo } from "@/app/components/sourcebotLogo";
33
import { getConfiguredLanguageModelsInfo } from "@/features/chat/utils.server";
44
import { CustomSlateEditor } from "@/features/chat/customSlateEditor";
@@ -35,6 +35,8 @@ export async function ChatLandingPage() {
3535
take: 10,
3636
});
3737

38+
const repoStats = await getReposStats();
39+
3840
if (isServiceError(allRepos)) {
3941
throw new ServiceErrorException(allRepos);
4042
}
@@ -47,6 +49,10 @@ export async function ChatLandingPage() {
4749
throw new ServiceErrorException(carouselRepos);
4850
}
4951

52+
if (isServiceError(repoStats)) {
53+
throw new ServiceErrorException(repoStats);
54+
}
55+
5056
const demoExamples = env.SOURCEBOT_DEMO_EXAMPLES_PATH ? await (async () => {
5157
try {
5258
return (await measure(() => loadJsonFile<DemoExamples>(env.SOURCEBOT_DEMO_EXAMPLES_PATH!, demoExamplesSchema), 'loadExamplesJsonFile')).data;
@@ -78,8 +84,7 @@ export async function ChatLandingPage() {
7884

7985
<div className="mt-8">
8086
<RepositoryCarousel
81-
// @nocheckin
82-
numberOfReposWithIndex={0}
87+
numberOfReposWithIndex={repoStats.numberOfReposWithIndex}
8388
displayRepos={carouselRepos}
8489
/>
8590
</div>

packages/web/src/app/(app)/repos/layout.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { getReposStats } from "@/actions";
2+
import { ServiceErrorException } from "@/lib/serviceError";
3+
import { isServiceError } from "@/lib/utils";
4+
15
interface LayoutProps {
26
children: React.ReactNode;
37
}
@@ -7,6 +11,11 @@ export default async function Layout(
711
) {
812
const { children } = props;
913

14+
const repoStats = await getReposStats();
15+
if (isServiceError(repoStats)) {
16+
throw new ServiceErrorException(repoStats);
17+
}
18+
1019
return (
1120
<div className="flex flex-col">
1221
<main className="flex-grow flex justify-center p-4 relative">

0 commit comments

Comments
 (0)