aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-06-18 16:13:54 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-06-18 16:13:54 +0200
commit528a9efa8272532bbd0dafc35c3e05e57c50f61e (patch)
tree62d4417df4ab9b2e53c44dc7271be81b88e4e0e5 /server/models
parentb2e4c0ba1a33b8a50491a1f8d111468a7da5640f (diff)
downloadPeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.tar.gz
PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.tar.zst
PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.zip
Try to make a better communication (between pods) module
Diffstat (limited to 'server/models')
-rw-r--r--server/models/pods.js15
-rw-r--r--server/models/requests.js32
2 files changed, 40 insertions, 7 deletions
diff --git a/server/models/pods.js b/server/models/pods.js
index 04cc2d6fc..daeadeb07 100644
--- a/server/models/pods.js
+++ b/server/models/pods.js
@@ -19,10 +19,13 @@ const PodsDB = mongoose.model('pods', podsSchema)
19const Pods = { 19const Pods = {
20 add: add, 20 add: add,
21 count: count, 21 count: count,
22 findById: findById,
22 findByUrl: findByUrl, 23 findByUrl: findByUrl,
23 findBadPods: findBadPods, 24 findBadPods: findBadPods,
24 incrementScores: incrementScores, 25 incrementScores: incrementScores,
25 list: list, 26 list: list,
27 listAllIds: listAllIds,
28 listAllUrls: listAllUrls,
26 remove: remove, 29 remove: remove,
27 removeAll: removeAll, 30 removeAll: removeAll,
28 removeAllByIds: removeAllByIds 31 removeAllByIds: removeAllByIds
@@ -48,6 +51,10 @@ function findBadPods (callback) {
48 PodsDB.find({ score: 0 }, callback) 51 PodsDB.find({ score: 0 }, callback)
49} 52}
50 53
54function findById (id, callback) {
55 PodsDB.findById(id, callback)
56}
57
51function findByUrl (url, callback) { 58function findByUrl (url, callback) {
52 PodsDB.findOne({ url: url }, callback) 59 PodsDB.findOne({ url: url }, callback)
53} 60}
@@ -68,6 +75,14 @@ function list (callback) {
68 }) 75 })
69} 76}
70 77
78function listAllIds (callback) {
79 return PodsDB.find({}, { _id: 1 }, callback)
80}
81
82function listAllUrls (callback) {
83 return PodsDB.find({}, { _id: 0, url: 1 }, callback)
84}
85
71function remove (url, callback) { 86function remove (url, callback) {
72 if (!callback) callback = function () {} 87 if (!callback) callback = function () {}
73 PodsDB.remove({ url: url }, callback) 88 PodsDB.remove({ url: url }, callback)
diff --git a/server/models/requests.js b/server/models/requests.js
index 2152ae0e9..e67ccad56 100644
--- a/server/models/requests.js
+++ b/server/models/requests.js
@@ -7,9 +7,8 @@ const logger = require('../helpers/logger')
7// --------------------------------------------------------------------------- 7// ---------------------------------------------------------------------------
8 8
9const requestsSchema = mongoose.Schema({ 9const requestsSchema = mongoose.Schema({
10 type: String, 10 request: mongoose.Schema.Types.Mixed,
11 id: String, // Special id to find duplicates (video created we want to remove...) 11 to: [ { type: mongoose.Schema.Types.ObjectId, ref: 'users' } ]
12 request: mongoose.Schema.Types.Mixed
13}) 12})
14const RequestsDB = mongoose.model('requests', requestsSchema) 13const RequestsDB = mongoose.model('requests', requestsSchema)
15 14
@@ -19,12 +18,15 @@ const Requests = {
19 create: create, 18 create: create,
20 findById: findById, 19 findById: findById,
21 list: list, 20 list: list,
21 removeAll: removeAll,
22 removePodOf: removePodOf,
22 removeRequestById: removeRequestById, 23 removeRequestById: removeRequestById,
23 removeRequests: removeRequests 24 removeRequests: removeRequests,
25 removeWithEmptyTo: removeWithEmptyTo
24} 26}
25 27
26function create (id, type, request, callback) { 28function create (request, to, callback) {
27 RequestsDB.create({ id: id, type: type, request: request }, callback) 29 RequestsDB.create({ request: request, to: to }, callback)
28} 30}
29 31
30function findById (id, callback) { 32function findById (id, callback) {
@@ -32,7 +34,17 @@ function findById (id, callback) {
32} 34}
33 35
34function list (callback) { 36function list (callback) {
35 RequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback) 37 RequestsDB.find({}, { _id: 1, request: 1, to: 1 }, callback)
38}
39
40function removeAll (callback) {
41 RequestsDB.remove({ }, callback)
42}
43
44function removePodOf (requestsIds, podId, callback) {
45 if (!callback) callback = function () {}
46
47 RequestsDB.update({ _id: { $in: requestsIds } }, { $pull: { to: podId } }, { multi: true }, callback)
36} 48}
37 49
38function removeRequestById (id, callback) { 50function removeRequestById (id, callback) {
@@ -50,6 +62,12 @@ function removeRequests (ids) {
50 }) 62 })
51} 63}
52 64
65function removeWithEmptyTo (callback) {
66 if (!callback) callback = function () {}
67
68 RequestsDB.remove({ to: { $size: 0 } }, callback)
69}
70
53// --------------------------------------------------------------------------- 71// ---------------------------------------------------------------------------
54 72
55module.exports = Requests 73module.exports = Requests