Skip to content

Commit

Permalink
limit to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Dec 4, 2024
1 parent 00e4a68 commit fd92160
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/db/src/schema/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,42 +232,45 @@ const buildCondition = (tx: Tx, cond: JobCondition): SQL => {
if (cond.type === JobFilterType.Deployment)
return exists(
tx
.select()
.select({ id: releaseJobTrigger.jobId })
.from(releaseJobTrigger)
.innerJoin(release, eq(releaseJobTrigger.releaseId, release.id))
.where(
and(
eq(release.deploymentId, cond.value),
eq(releaseJobTrigger.jobId, job.id),
),
),
)
.limit(1),
);
if (cond.type === JobFilterType.Environment)
return exists(
tx
.select()
.select({ id: releaseJobTrigger.jobId })
.from(releaseJobTrigger)
.where(
and(
eq(releaseJobTrigger.environmentId, cond.value),
eq(releaseJobTrigger.jobId, job.id),
),
),
)
.limit(1),
);
if (cond.type === FilterType.Version)
return exists(
tx
.select()
.select({ id: releaseJobTrigger.jobId })
.from(releaseJobTrigger)
.innerJoin(release, eq(releaseJobTrigger.releaseId, release.id))
.where(
and(eq(releaseJobTrigger.jobId, job.id), buildVersionCondition(cond)),
),
)
.limit(1),
);
if (cond.type === JobFilterType.JobTarget)
return exists(
tx
.select()
.select({ id: releaseJobTrigger.jobId })
.from(releaseJobTrigger)
.innerJoin(resource, eq(releaseJobTrigger.resourceId, resource.id))
.where(
Expand All @@ -276,19 +279,21 @@ const buildCondition = (tx: Tx, cond: JobCondition): SQL => {
eq(releaseJobTrigger.resourceId, cond.value),
isNull(resource.deletedAt),
),
),
)
.limit(1),
);
if (cond.type === JobFilterType.Release)
return exists(
tx
.select()
.select({ id: releaseJobTrigger.jobId })
.from(releaseJobTrigger)
.where(
and(
eq(releaseJobTrigger.jobId, job.id),
eq(releaseJobTrigger.releaseId, cond.value),
),
),
)
.limit(1),
);

const subCon = cond.conditions.map((c) => buildCondition(tx, c));
Expand Down

0 comments on commit fd92160

Please sign in to comment.