aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-23 19:14:28 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-26 20:28:34 +0200
commit43666d616d286ba64ce237facd7e247da7fb9d3c (patch)
tree145a532d714f69654680c5cdfd2ec970d15dbb1a
parent5e9acecaebb1474bec2a800b85f0d5352c5f0580 (diff)
downloadPeerTube-43666d616d286ba64ce237facd7e247da7fb9d3c.tar.gz
PeerTube-43666d616d286ba64ce237facd7e247da7fb9d3c.tar.zst
PeerTube-43666d616d286ba64ce237facd7e247da7fb9d3c.zip
Server: randomize the requests list
We don't want to stuck with the same failing requests
-rw-r--r--server/models/request.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/server/models/request.js b/server/models/request.js
index f11c20b52..34a4287ea 100644
--- a/server/models/request.js
+++ b/server/models/request.js
@@ -128,7 +128,9 @@ function makeRequest (toPod, requestsToMake, callback) {
128function makeRequests () { 128function makeRequests () {
129 const self = this 129 const self = this
130 130
131 listWithLimit.call(self, constants.REQUESTS_LIMIT, function (err, requests) { 131 // We limit the size of the requests (REQUESTS_LIMIT)
132 // We don't want to stuck with the same failing requests so we get a random list
133 listWithLimitAndRandom.call(self, constants.REQUESTS_LIMIT, function (err, requests) {
132 if (err) { 134 if (err) {
133 logger.error('Cannot get the list of requests.', { err: err }) 135 logger.error('Cannot get the list of requests.', { err: err })
134 return // Abort 136 return // Abort
@@ -249,8 +251,17 @@ function updatePodsScore (goodPods, badPods) {
249 }) 251 })
250} 252}
251 253
252function listWithLimit (limit, callback) { 254function listWithLimitAndRandom (limit, callback) {
253 this.find({ }, { _id: 1, request: 1, to: 1 }).sort({ _id: 1 }).limit(limit).exec(callback) 255 const self = this
256
257 self.count(function (err, count) {
258 if (err) return callback(err)
259
260 let start = Math.floor(Math.random() * count) - limit
261 if (start < 0) start = 0
262
263 self.find({ }, { _id: 1, request: 1, to: 1 }).sort({ _id: 1 }).skip(start).limit(limit).exec(callback)
264 })
254} 265}
255 266
256function removeAll (callback) { 267function removeAll (callback) {