Server: add config endpoint
[oweals/peertube.git] / server / lib / request-video-qadu-scheduler.js
index 29e44a6c465973439855f9b710d62b0ebf34b1a0..a85d35160a7a36ab75a3426900881f6b98c0f3d1 100644 (file)
@@ -6,7 +6,6 @@ const db = require('../initializers/database')
 const logger = require('../helpers/logger')
 
 module.exports = class RequestVideoQaduScheduler extends BaseRequestScheduler {
-
   constructor () {
     super()
 
@@ -38,18 +37,16 @@ module.exports = class RequestVideoQaduScheduler extends BaseRequestScheduler {
         if (!requestsToMakeGrouped[hashKey]) {
           requestsToMakeGrouped[hashKey] = {
             toPod: pod,
-            endpoint: constants.REQUEST_ENDPOINTS.QADU,
+            endpoint: constants.REQUEST_VIDEO_QADU_ENDPOINT,
             ids: [], // request ids, to delete them from the DB in the future
             datas: [], // requests data
             videos: {}
           }
         }
 
-        if (!requestsToMakeGrouped[hashKey].videos[video.id]) {
-          requestsToMakeGrouped[hashKey].videos[video.id] = {}
-        }
-
-        const videoData = requestsToMakeGrouped[hashKey].videos[video.id]
+        // Maybe another attribute was filled for this video
+        let videoData = requestsToMakeGrouped[hashKey].videos[video.id]
+        if (!videoData) videoData = {}
 
         switch (request.type) {
           case constants.REQUEST_VIDEO_QADU_TYPES.LIKES:
@@ -57,7 +54,7 @@ module.exports = class RequestVideoQaduScheduler extends BaseRequestScheduler {
             break
 
           case constants.REQUEST_VIDEO_QADU_TYPES.DISLIKES:
-            videoData.likes = video.dislikes
+            videoData.dislikes = video.dislikes
             break
 
           case constants.REQUEST_VIDEO_QADU_TYPES.VIEWS:
@@ -72,10 +69,14 @@ module.exports = class RequestVideoQaduScheduler extends BaseRequestScheduler {
         // Do not forget the remoteId so the remote pod can identify the video
         videoData.remoteId = video.id
         requestsToMakeGrouped[hashKey].ids.push(request.id)
+
+        // Maybe there are multiple quick and dirty update for the same video
+        // We use this hashmap to dedupe them
         requestsToMakeGrouped[hashKey].videos[video.id] = videoData
       })
     })
 
+    // Now we deduped similar quick and dirty updates, we can build our requests datas
     Object.keys(requestsToMakeGrouped).forEach(hashKey => {
       Object.keys(requestsToMakeGrouped[hashKey].videos).forEach(videoId => {
         const videoData = requestsToMakeGrouped[hashKey].videos[videoId]