From fbf1134e3e6b386c9ec5a3946c61f3faf84397fb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 13 May 2016 18:10:46 +0200 Subject: Introduce paginations in videos listing --- server/models/videos.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'server/models') diff --git a/server/models/videos.js b/server/models/videos.js index eaea35b7f..aa9ed687d 100644 --- a/server/models/videos.js +++ b/server/models/videos.js @@ -76,8 +76,8 @@ function get (id, callback) { }) } -function list (callback) { - VideosDB.find(function (err, videosList) { +function list (start, count, callback) { + VideosDB.find({}).skip(start).limit(start + count).exec(function (err, videosList) { if (err) { logger.error('Cannot get the list of the videos.') return callback(err) @@ -125,8 +125,9 @@ function removeByIds (ids, callback) { VideosDB.remove({ _id: { $in: ids } }, callback) } -function search (name, callback) { - VideosDB.find({ name: new RegExp(name) }, function (err, videos) { +function search (name, start, count, callback) { + VideosDB.find({ name: new RegExp(name) }).skip(start).limit(start + count) + .exec(function (err, videos) { if (err) { logger.error('Cannot search the videos.') return callback(err) -- cgit v1.2.3