parseInt fixes getObjects fix

v1.18.x
Baris Soner Usakli 11 years ago
parent 3a7fcc2d3d
commit 097810a057

@ -62,8 +62,6 @@
callback(err);
});
}
@ -132,20 +130,15 @@
module.info = function(callback) {
db.stats({scale:1024}, function(err, stats) {
db.serverStatus(function(err, serverStatus) {
stats.avgObjSize = (stats.avgObjSize / 1024).toFixed(2);
stats.avgObjSize = (stats.avgObjSize / 1024).toFixed(2);
stats.serverStatus = serverStatus;
stats.raw = JSON.stringify(stats, null, 4);
stats.raw = JSON.stringify(stats, null, 4);
stats.mongo = true;
//remove this when andrew adds in undefined checking to templates
stats.redis = false;
callback(err, stats);
stats.mongo = true;
//remove this when andrew adds in undefined checking to templates
stats.redis = false;
callback(err, stats);
});
});
}
@ -242,6 +235,7 @@
}
module.getObjects = function(keys, callback) {
db.collection('objects').find({_key:{$in:keys}}, {_id:0}).toArray(function(err, data) {
if(err) {
@ -251,15 +245,27 @@
var returnData = [],
resultIndex = 0;
for(var i=0; i<keys.length; ++i) {
if(data && resultIndex < data.length && keys[i] === data[resultIndex]._key) {
delete data[resultIndex]._key;
returnData.push(data[resultIndex]);
++resultIndex;
} else {
returnData.push(null);
function findData(key) {
if(!data) {
return null;
}
for(var i=0; i<data.length; ++i) {
if(data[i]._key === key) {
var item = data.splice(i, 1);
if(item && item.length) {
return item[0];
} else {
return null;
}
}
}
return null;
}
for(var i=0; i<keys.length; ++i) {
returnData.push(findData(keys[i]));
}
callback(err, returnData);

@ -58,7 +58,7 @@
results.base.count = results.users.length;
results.base.members = results.users;
results.base.deletable = (results.base.gid !== '1');
results.base.deletable = parseInt(results.base.gid, 10) !== 1;
callback(err, results.base);
});

@ -81,7 +81,7 @@ var db = require('./database'),
}
Messaging.updateChatTime = function(uid, toUid, callback) {
RDB.zadd('uid:' + uid + ':chats', Date.now(), toUid, function(err) {
db.sortedSetAdd('uid:' + uid + ':chats', Date.now(), toUid, function(err) {
if (callback) {
callback(err);
}
@ -89,7 +89,7 @@ var db = require('./database'),
};
Messaging.getRecentChats = function(uid, callback) {
RDB.zrevrange('uid:' + uid + ':chats', 0, 9, function(err, uids) {
db.getSortedSetRevRange('uid:' + uid + ':chats', 0, 9, function(err, uids) {
if (!err) {
user.getMultipleUserFields(uids, ['username', 'picture', 'uid'], callback);
} else {

@ -377,7 +377,7 @@ var db = require('./database'),
try {
postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString();
postData.relativeEditTime = postData.edited !== '0' ? (new Date(parseInt(postData.edited,10)).toISOString()) : '';
postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? (new Date(parseInt(postData.edited, 10)).toISOString()) : '';
} catch(e) {
winston.err('invalid time value');
}
@ -457,8 +457,10 @@ var db = require('./database'),
Posts.getPostsByUid = function(uid, start, end, callback) {
user.getPostIds(uid, start, end, function(pids) {
if (pids && pids.length) {
plugins.fireHook('filter:post.getTopic', pids, function(err, posts) {
if (!err & 0 < posts.length) {
Posts.getPostsByPids(pids, function(err, posts) {
plugins.fireHook('action:post.gotTopic', posts);

@ -409,9 +409,10 @@ var DebugRoute = function(app) {
function(next) {
/*db.searchIndex('post', 'green tomato is healthy', 2);
next();*/
db.search('post', 'tomato', function(err, result) {
/*db.search('post', 'tomato', function(err, result) {
next(err, result);
});
});*/
db.getObjects(['deeerp', 'user:1', 'bonanza', 'post:1'], next);
}
];

@ -383,13 +383,15 @@ var fs = require('fs'),
posts.getPostsByUid(userData.theirid, 0, 9, function (posts) {
userData.posts = posts.filter(function (p) {
return p && p.deleted !== "1";
return p && parseInt(p.deleted, 10) !== 1;
});
userData.isFollowing = isFollowing;
if (!userData.profileviews)
if (!userData.profileviews) {
userData.profileviews = 1;
if (callerUID !== userData.uid)
}
if (callerUID !== userData.uid) {
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
}
postTools.parse(userData.signature, function (err, signature) {
userData.signature = signature;

@ -45,7 +45,7 @@ var path = require('path'),
var topicUrls = [];
topics.getAllTopics(null, null, function(err, topics) {
topics.forEach(function(topic) {
if (topic.deleted !== '1') {
if (parseInt(topic.deleted, 10) !== 1) {
topicUrls.push({
url: path.join('topic', topic.slug),
changefreq: 'daily',

@ -514,7 +514,7 @@ var bcrypt = require('bcrypt'),
console.log(err);
} else {
userIds = userIds.filter(function(value) {
return value !== '0';
return parseInt(value, 10) !== 0;
});
callback(userIds.length);
}
@ -527,7 +527,7 @@ var bcrypt = require('bcrypt'),
console.log(err);
} else {
userIds = userIds.filter(function(value) {
return value !== '0';
return parseInt(value, 10) !== 0;
});
callback(userIds.length);
}

@ -409,7 +409,7 @@ var path = require('path'),
"categories": function (next) {
categories.getAllCategories(0, function (err, returnData) {
returnData.categories = returnData.categories.filter(function (category) {
if (category.disabled !== '1') {
if (parseInt(category.disabled, 10) !== 1) {
return true;
} else {
return false;

Loading…
Cancel
Save