mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-22 08:46:54 -06:00
Server: optimize function to see if there are users or not
This commit is contained in:
parent
0ff21c1c08
commit
089ff2f204
@ -39,10 +39,10 @@ function clientsExist (callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function usersExist (callback) {
|
function usersExist (callback) {
|
||||||
User.list(function (err, users) {
|
User.count(function (err, totalUsers) {
|
||||||
if (err) return callback(err)
|
if (err) return callback(err)
|
||||||
|
|
||||||
return callback(null, users.length !== 0)
|
return callback(null, totalUsers !== 0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ UserSchema.methods = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserSchema.statics = {
|
UserSchema.statics = {
|
||||||
|
count: count,
|
||||||
getByUsernameAndPassword: getByUsernameAndPassword,
|
getByUsernameAndPassword: getByUsernameAndPassword,
|
||||||
list: list,
|
list: list,
|
||||||
loadById: loadById,
|
loadById: loadById,
|
||||||
@ -29,6 +30,10 @@ mongoose.model('User', UserSchema)
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function count (callback) {
|
||||||
|
return this.count(callback)
|
||||||
|
}
|
||||||
|
|
||||||
function getByUsernameAndPassword (username, password) {
|
function getByUsernameAndPassword (username, password) {
|
||||||
return this.findOne({ username: username, password: password })
|
return this.findOne({ username: username, password: password })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user