X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Ftag.ts;h=653b9694b8a6adef8a3c68cfb8b1822e6c2667c3;hb=4e56f0fff12ab9840574e7a27277fc78b195b3e2;hp=7900e070dd8a0dfa4205859b20fb081fc1dc49ed;hpb=c3edc5b074aa4bb1861ed0a94d3713808e87170f;p=github%2FChocobozzz%2FPeerTube.git 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)