mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 19:21:04 +01:00
less db calls
no db call for settings if uid 0 no db call for isFollowing if uid 0
This commit is contained in:
@@ -15,6 +15,9 @@ module.exports = function(Topics) {
|
||||
|
||||
|
||||
Topics.isFollowing = function(tid, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback(null, false);
|
||||
}
|
||||
db.isSetMember('tid:' + tid + ':followers', uid, callback);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var meta = require('./../meta'),
|
||||
db = require('./../database'),
|
||||
plugins = require('./../plugins');
|
||||
var meta = require('../meta'),
|
||||
db = require('../database'),
|
||||
plugins = require('../plugins');
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
User.getSettings = function(uid, callback) {
|
||||
db.getObject('user:' + uid + ':settings', function(err, settings) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(!settings) {
|
||||
settings = {};
|
||||
}
|
||||
|
||||
function onSettingsLoaded(settings) {
|
||||
plugins.fireHook('filter:user.getSettings', {uid: uid, settings: settings}, function(err, data) {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -41,6 +33,18 @@ module.exports = function(User) {
|
||||
|
||||
callback(null, settings);
|
||||
});
|
||||
}
|
||||
|
||||
if (!parseInt(uid, 10)) {
|
||||
return onSettingsLoaded({});
|
||||
}
|
||||
|
||||
db.getObject('user:' + uid + ':settings', function(err, settings) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
onSettingsLoaded(settings ? settings : {});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user