From f282639b07deee1e35403bd86c46ea521fb4845e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 26 Feb 2017 19:27:08 +0100 Subject: [PATCH] Server: request scheduler refractoring --- server/lib/base-request-scheduler.js | 8 -------- server/lib/request-video-qadu-scheduler.js | 11 +++++------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/server/lib/base-request-scheduler.js b/server/lib/base-request-scheduler.js index d15680c25..309c1a261 100644 --- a/server/lib/base-request-scheduler.js +++ b/server/lib/base-request-scheduler.js @@ -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) diff --git a/server/lib/request-video-qadu-scheduler.js b/server/lib/request-video-qadu-scheduler.js index 29e44a6c4..33b1c6d28 100644 --- a/server/lib/request-video-qadu-scheduler.js +++ b/server/lib/request-video-qadu-scheduler.js @@ -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] -- 2.25.1