From f2623febd8b7b818e47d995ae59f4f1d2f37961b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 23 Jun 2022 11:01:44 +0200 Subject: Fix duplicated tags error --- server/models/video/tag.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index 7900e070d..653b9694b 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts @@ -45,8 +45,9 @@ export class TagModel extends Model>> { static findOrCreateTags (tags: string[], transaction: Transaction): Promise { if (tags === null) return Promise.resolve([]) - const tasks: Promise[] = [] - tags.forEach(tag => { + const uniqueTags = new Set(tags) + + const tasks = Array.from(uniqueTags).map(tag => { const query = { where: { name: tag @@ -57,9 +58,8 @@ export class TagModel extends Model>> { transaction } - const promise = TagModel.findOrCreate(query) + return TagModel.findOrCreate(query) .then(([ tagInstance ]) => tagInstance) - tasks.push(promise) }) return Promise.all(tasks) -- cgit v1.2.3