Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fixed edge case

Steven Teyf6a48d60e723
diff --git a/apps/web/app/api/cron/import/short/utils.ts b/apps/web/app/api/cron/import/short/utils.ts
index b4bcc06e64..3695493a6a 100644
--- a/apps/web/app/api/cron/import/short/utils.ts
+++ b/apps/web/app/api/cron/import/short/utils.ts
@@ -79,12 +79,24 @@ export const importLinksFromShort = async ({
// import tags into database
if (importTags && tagsToCreate.size > 0) {
- await prisma.tag.createMany({
- data: Array.from(tagsToCreate).map((tag) => ({
- name: tag,
- color: randomBadgeColor(),
+ const existingTags = await prisma.tag.findMany({
+ where: {
projectId,
- })),
+ },
+ select: {
+ id: true,
+ name: true,
+ },
+ });
+ await prisma.tag.createMany({
+ data: Array.from(tagsToCreate)
+ // filter out existing tags with the same name
+ .filter((tag) => !existingTags.some((t) => t.name === tag))
+ .map((tag) => ({
+ name: tag,
+ color: randomBadgeColor(),
+ projectId,
+ })),
skipDuplicates: true,
});
allTags = await prisma.tag.findMany({