aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/tag.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/tag.ts')
-rw-r--r--server/models/video/tag.ts24
1 files changed, 8 insertions, 16 deletions
diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts
index 3c657d751..d0d8353d7 100644
--- a/server/models/video/tag.ts
+++ b/server/models/video/tag.ts
@@ -1,9 +1,8 @@
1import { each } from 'async'
2import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3 3
4import { addMethodsToModel } from '../utils' 4import { addMethodsToModel } from '../utils'
5import { 5import {
6 TagClass,
7 TagInstance, 6 TagInstance,
8 TagAttributes, 7 TagAttributes,
9 8
@@ -52,10 +51,9 @@ function associate (models) {
52 }) 51 })
53} 52}
54 53
55findOrCreateTags = function (tags: string[], transaction: Sequelize.Transaction, callback: TagMethods.FindOrCreateTagsCallback) { 54findOrCreateTags = function (tags: string[], transaction: Sequelize.Transaction) {
56 const tagInstances = [] 55 const tasks: Promise<TagInstance>[] = []
57 56 tags.forEach(tag => {
58 each<string, Error>(tags, function (tag, callbackEach) {
59 const query: any = { 57 const query: any = {
60 where: { 58 where: {
61 name: tag 59 name: tag
@@ -67,15 +65,9 @@ findOrCreateTags = function (tags: string[], transaction: Sequelize.Transaction,
67 65
68 if (transaction) query.transaction = transaction 66 if (transaction) query.transaction = transaction
69 67
70 Tag.findOrCreate(query).asCallback(function (err, res) { 68 const promise = Tag.findOrCreate(query).then(([ tagInstance ]) => tagInstance)
71 if (err) return callbackEach(err) 69 tasks.push(promise)
72
73 // res = [ tag, isCreated ]
74 const tag = res[0]
75 tagInstances.push(tag)
76 return callbackEach()
77 })
78 }, function (err) {
79 return callback(err, tagInstances)
80 }) 70 })
71
72 return Promise.all(tasks)
81} 73}