Server: request scheduler refractoring
authorChocobozzz <florian.bigard@gmail.com>
Sun, 26 Feb 2017 18:27:08 +0000 (19:27 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Sun, 26 Feb 2017 19:01:26 +0000 (20:01 +0100)
server/lib/base-request-scheduler.js
server/lib/request-video-qadu-scheduler.js

index d15680c25a5789b227e29eb56b5e8eaa120e148e..309c1a26166c06ec22c4b4161fb45ca4f7e1eedf 100644 (file)
@@ -95,14 +95,6 @@ module.exports = class BaseRequestScheduler {
         const requestToMake = requestsToMakeGrouped[hashKey]
         const toPod = requestToMake.toPod
 
-        // Maybe the pod is not our friend anymore so simply remove it
-        if (!toPod) {
-          const requestIdsToDelete = requestToMake.ids
-
-          logger.info('Removing %d "%s" of unexisting pod %s.', requestIdsToDelete.length, this.description, requestToMake.toPod.id)
-          return this.getRequestToPodModel().removePodOf(requestIdsToDelete, requestToMake.toPod.id, callbackEach)
-        }
-
         this.makeRequest(toPod, requestToMake.endpoint, requestToMake.datas, (success) => {
           if (success === false) {
             badPods.push(requestToMake.toPod.id)
index 29e44a6c465973439855f9b710d62b0ebf34b1a0..33b1c6d2863ff23a14a133c1c7186af7bd8ed38e 100644 (file)
@@ -45,12 +45,7 @@ module.exports = class RequestVideoQaduScheduler extends BaseRequestScheduler {
           }
         }
 
-        if (!requestsToMakeGrouped[hashKey].videos[video.id]) {
-          requestsToMakeGrouped[hashKey].videos[video.id] = {}
-        }
-
-        const videoData = requestsToMakeGrouped[hashKey].videos[video.id]
-
+        const videoData = {}
         switch (request.type) {
           case constants.REQUEST_VIDEO_QADU_TYPES.LIKES:
             videoData.likes = video.likes
@@ -72,10 +67,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]