diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-16 21:51:35 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-16 21:51:35 +0200 |
commit | 089ff2f2046fdbaf9531726eea1f8c6726ebf0c0 (patch) | |
tree | 5bfe45deb458dd0329c62ff5d22eb5c7e3e38ec6 | |
parent | 0ff21c1c086f907612e34880f76f08bc74eeb78c (diff) | |
download | PeerTube-089ff2f2046fdbaf9531726eea1f8c6726ebf0c0.tar.gz PeerTube-089ff2f2046fdbaf9531726eea1f8c6726ebf0c0.tar.zst PeerTube-089ff2f2046fdbaf9531726eea1f8c6726ebf0c0.zip |
Server: optimize function to see if there are users or not
-rw-r--r-- | server/initializers/checker.js | 4 | ||||
-rw-r--r-- | server/models/user.js | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/server/initializers/checker.js b/server/initializers/checker.js index 3831efb8d..871d3cac2 100644 --- a/server/initializers/checker.js +++ b/server/initializers/checker.js | |||
@@ -39,10 +39,10 @@ function clientsExist (callback) { | |||
39 | } | 39 | } |
40 | 40 | ||
41 | function usersExist (callback) { | 41 | function usersExist (callback) { |
42 | User.list(function (err, users) { | 42 | User.count(function (err, totalUsers) { |
43 | if (err) return callback(err) | 43 | if (err) return callback(err) |
44 | 44 | ||
45 | return callback(null, users.length !== 0) | 45 | return callback(null, totalUsers !== 0) |
46 | }) | 46 | }) |
47 | } | 47 | } |
48 | 48 | ||
diff --git a/server/models/user.js b/server/models/user.js index 351ffef86..d289da19a 100644 --- a/server/models/user.js +++ b/server/models/user.js | |||
@@ -19,6 +19,7 @@ UserSchema.methods = { | |||
19 | } | 19 | } |
20 | 20 | ||
21 | UserSchema.statics = { | 21 | UserSchema.statics = { |
22 | count: count, | ||
22 | getByUsernameAndPassword: getByUsernameAndPassword, | 23 | getByUsernameAndPassword: getByUsernameAndPassword, |
23 | list: list, | 24 | list: list, |
24 | loadById: loadById, | 25 | loadById: loadById, |
@@ -29,6 +30,10 @@ mongoose.model('User', UserSchema) | |||
29 | 30 | ||
30 | // --------------------------------------------------------------------------- | 31 | // --------------------------------------------------------------------------- |
31 | 32 | ||
33 | function count (callback) { | ||
34 | return this.count(callback) | ||
35 | } | ||
36 | |||
32 | function getByUsernameAndPassword (username, password) { | 37 | function getByUsernameAndPassword (username, password) { |
33 | return this.findOne({ username: username, password: password }) | 38 | return this.findOne({ username: username, password: password }) |
34 | } | 39 | } |