diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-23 11:01:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-23 11:01:44 +0200 |
commit | f2623febd8b7b818e47d995ae59f4f1d2f37961b (patch) | |
tree | ffd279a61d2e2f809d3db380fc02d0cab3d1b364 /server/models/video | |
parent | b6898035bfc5ba60ec54f7e61ff832e5e2ac30eb (diff) | |
download | PeerTube-f2623febd8b7b818e47d995ae59f4f1d2f37961b.tar.gz PeerTube-f2623febd8b7b818e47d995ae59f4f1d2f37961b.tar.zst PeerTube-f2623febd8b7b818e47d995ae59f4f1d2f37961b.zip |
Fix duplicated tags error
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/tag.ts | 8 |
1 files changed, 4 insertions, 4 deletions
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<Partial<AttributesOnly<TagModel>>> { | |||
45 | static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> { | 45 | static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> { |
46 | if (tags === null) return Promise.resolve([]) | 46 | if (tags === null) return Promise.resolve([]) |
47 | 47 | ||
48 | const tasks: Promise<MTag>[] = [] | 48 | const uniqueTags = new Set(tags) |
49 | tags.forEach(tag => { | 49 | |
50 | const tasks = Array.from(uniqueTags).map(tag => { | ||
50 | const query = { | 51 | const query = { |
51 | where: { | 52 | where: { |
52 | name: tag | 53 | name: tag |
@@ -57,9 +58,8 @@ export class TagModel extends Model<Partial<AttributesOnly<TagModel>>> { | |||
57 | transaction | 58 | transaction |
58 | } | 59 | } |
59 | 60 | ||
60 | const promise = TagModel.findOrCreate<MTag>(query) | 61 | return TagModel.findOrCreate<MTag>(query) |
61 | .then(([ tagInstance ]) => tagInstance) | 62 | .then(([ tagInstance ]) => tagInstance) |
62 | tasks.push(promise) | ||
63 | }) | 63 | }) |
64 | 64 | ||
65 | return Promise.all(tasks) | 65 | return Promise.all(tasks) |