Speed up populate database script
authorChocobozzz <me@florianbigard.com>
Wed, 18 Jul 2018 12:17:54 +0000 (14:17 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 24 Jul 2018 12:04:05 +0000 (14:04 +0200)
server/controllers/api/videos/rate.ts
server/tests/real-world/populate-database.ts

index 9d63b582163a392aa86ae4f1d099b5561b893dcf..b1732837d1518c08f7e58a85b2863e5a0e91ffe1 100644 (file)
@@ -67,8 +67,6 @@ async function rateVideo (req: express.Request, res: express.Response) {
       dislikes: dislikesToIncrement
     }
 
-    // Even if we do not own the video we increment the attributes
-    // It is useful for the user to have a feedback
     await videoInstance.increment(incrementQuery, sequelizeOptions)
 
     await sendVideoRateChange(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
index f0f82f7f8cf2fd587906a52c89cb8a5373eaae68..d41ac8d3633b5be286b221e14e6305e3934fd5be 100644 (file)
@@ -38,15 +38,26 @@ async function start () {
 
   // Forever
   const fakeTab = Array.from(Array(1000000).keys())
-  await Bluebird.map(fakeTab, () => {
-    return Promise.all([
-      uploadCustom(server),
-      likeCustom(server),
-      dislikeCustom(server),
-      createUserCustom(server),
-      createCustomChannel(server)
-    ]).catch(err => console.error(err))
-  }, { concurrency: 5 })
+  const funs = [
+    uploadCustom
+    // uploadCustom,
+    // uploadCustom,
+    // uploadCustom,
+    // likeCustom,
+    // createUserCustom,
+    // createCustomChannel
+  ]
+  const promises = []
+
+  for (const fun of funs) {
+    promises.push(
+      Bluebird.map(fakeTab, () => {
+        return fun(server).catch(err => console.error(err))
+      }, { concurrency: 3 })
+    )
+  }
+
+  await Promise.all(promises)
 }
 
 function getRandomInt (min, max) {