]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/request.js
Server: show user created date for the api
[github/Chocobozzz/PeerTube.git] / server / models / request.js
index 248ab330306735cfd693da8bc32139bb617b8596..4e510e18aec84d040aeea42092f63374369e5d11 100644 (file)
@@ -1,8 +1,10 @@
 'use strict'
 
-const async = require('async')
+const each = require('async/each')
+const eachLimit = require('async/eachLimit')
 const map = require('lodash/map')
 const mongoose = require('mongoose')
+const waterfall = require('async/waterfall')
 
 const constants = require('../initializers/constants')
 const logger = require('../helpers/logger')
@@ -17,14 +19,15 @@ let timer = null
 
 const RequestSchema = mongoose.Schema({
   request: mongoose.Schema.Types.Mixed,
-  to: [ { type: mongoose.Schema.Types.ObjectId, ref: 'users' } ]
+  to: [ { type: mongoose.Schema.Types.ObjectId, ref: 'Pod' } ]
 })
 
 RequestSchema.statics = {
   activate,
   deactivate,
   flush,
-  forceSend
+  forceSend,
+  list
 }
 
 RequestSchema.pre('save', function (next) {
@@ -51,7 +54,7 @@ mongoose.model('Request', RequestSchema)
 
 function activate () {
   logger.info('Requests scheduler activated.')
-  timer = setInterval(makeRequests.bind(this), constants.INTERVAL)
+  timer = setInterval(makeRequests.bind(this), constants.REQUESTS_INTERVAL)
 }
 
 function deactivate () {
@@ -70,6 +73,10 @@ function forceSend () {
   makeRequests.call(this)
 }
 
+function list (callback) {
+  this.find({ }, callback)
+}
+
 // ---------------------------------------------------------------------------
 
 // Make a requests to friends of a certain type
@@ -136,7 +143,7 @@ function makeRequests () {
     const goodPods = []
     const badPods = []
 
-    async.eachLimit(Object.keys(requestsToMake), constants.REQUESTS_IN_PARALLEL, function (toPodId, callbackEach) {
+    eachLimit(Object.keys(requestsToMake), constants.REQUESTS_IN_PARALLEL, function (toPodId, callbackEach) {
       const requestToMake = requestsToMake[toPodId]
 
       // FIXME: mongodb request inside a loop :/
@@ -183,7 +190,7 @@ function makeRequests () {
 
 // Remove pods with a score of 0 (too many requests where they were unreachable)
 function removeBadPods () {
-  async.waterfall([
+  waterfall([
     function findBadPods (callback) {
       Pod.listBadPods(function (err, pods) {
         if (err) {
@@ -217,7 +224,7 @@ function removeBadPods () {
         return callback(null)
       }
 
-      async.each(videosList, function (video, callbackEach) {
+      each(videosList, function (video, callbackEach) {
         video.remove(callbackEach)
       }, function (err) {
         if (err) {
@@ -237,7 +244,7 @@ function removeBadPods () {
         return callback(null)
       }
 
-      async.each(pods, function (pod, callbackEach) {
+      each(pods, function (pod, callbackEach) {
         pod.remove(callbackEach)
       }, function (err) {
         if (err) return callback(err)