-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: stop creating TaskRunTag records and join table entries during triggering #3369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ericallam
merged 4 commits into
main
from
feature/tri-8451-batch-taskruntag-upserts-in-trigger-and-batch-trigger-paths
Apr 14, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d63d41f
fix: stop creating TaskRunTag records and join table entries during t…
ericallam 197c3fe
Remove all TaskRun.tags readers and replace with TaskRun.runTags
ericallam b5e19ff
remove duplicate runTags: true selector
ericallam 9f6da36
filter out tags that are empty or just whitespace
ericallam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: improvement | ||
| --- | ||
|
|
||
| Stop creating TaskRunTag records and _TaskRunToTaskRunTag join table entries during task triggering. The denormalized runTags string array on TaskRun already stores tag names, making the M2M relation redundant write overhead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,108 +1 @@ | ||
| import { Prisma } from "@trigger.dev/database"; | ||
| import { prisma } from "~/db.server"; | ||
| import { generateFriendlyId } from "~/v3/friendlyIdentifiers"; | ||
| import { PrismaClientOrTransaction } from "@trigger.dev/database"; | ||
|
|
||
| export const MAX_TAGS_PER_RUN = 10; | ||
| const MAX_RETRIES = 3; | ||
|
|
||
| export async function createTag( | ||
| { tag, projectId }: { tag: string; projectId: string }, | ||
| prismaClient: PrismaClientOrTransaction = prisma | ||
| ) { | ||
| if (tag.trim().length === 0) return; | ||
|
|
||
| let attempts = 0; | ||
| const friendlyId = generateFriendlyId("runtag"); | ||
|
|
||
| while (attempts < MAX_RETRIES) { | ||
| try { | ||
| return await prisma.taskRunTag.upsert({ | ||
| where: { | ||
| projectId_name: { | ||
| projectId, | ||
| name: tag, | ||
| }, | ||
| }, | ||
| create: { | ||
| friendlyId, | ||
| name: tag, | ||
| projectId, | ||
| }, | ||
| update: {}, | ||
| }); | ||
| } catch (error) { | ||
| if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") { | ||
| // Handle unique constraint violation (conflict) | ||
| attempts++; | ||
| if (attempts >= MAX_RETRIES) { | ||
| throw new Error(`Failed to create tag after ${MAX_RETRIES} attempts due to conflicts.`); | ||
| } | ||
| } else { | ||
| throw error; // Re-throw other errors | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export type TagRecord = { | ||
| id: string; | ||
| name: string; | ||
| }; | ||
|
|
||
| export async function createTags( | ||
| { | ||
| tags, | ||
| projectId, | ||
| }: { | ||
| tags: string | string[] | undefined; | ||
| projectId: string; | ||
| }, | ||
| prismaClient: PrismaClientOrTransaction = prisma | ||
| ): Promise<TagRecord[]> { | ||
| if (!tags) { | ||
| return []; | ||
| } | ||
|
|
||
| const tagsArray = typeof tags === "string" ? [tags] : tags; | ||
|
|
||
| if (tagsArray.length === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| const tagRecords: TagRecord[] = []; | ||
| for (const tag of tagsArray) { | ||
| const tagRecord = await createTag( | ||
| { | ||
| tag, | ||
| projectId, | ||
| }, | ||
| prismaClient | ||
| ); | ||
| if (tagRecord) { | ||
| tagRecords.push({ id: tagRecord.id, name: tagRecord.name }); | ||
| } | ||
| } | ||
|
|
||
| return tagRecords; | ||
| } | ||
|
|
||
| export async function getTagsForRunId({ | ||
| friendlyId, | ||
| environmentId, | ||
| }: { | ||
| friendlyId: string; | ||
| environmentId: string; | ||
| }) { | ||
| const run = await prisma.taskRun.findFirst({ | ||
| where: { | ||
| friendlyId, | ||
| runtimeEnvironmentId: environmentId, | ||
| }, | ||
| select: { | ||
| tags: true, | ||
| }, | ||
| }); | ||
|
|
||
| return run?.tags ?? undefined; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.