Skip to content

Node.js based forum software built for the modern web

parseInt fixes getObjects fix

Baris Soner Usakli097810a057f5
diff --git a/src/database/mongo.js b/src/database/mongo.js
index 0c538cd103..0c7552ff2f 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -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);
diff --git a/src/groups.js b/src/groups.js
index da521a75af..3d56520257 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -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);
});
diff --git a/src/messaging.js b/src/messaging.js
index 5e96a6c967..948f715448 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -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 {
diff --git a/src/posts.js b/src/posts.js
index 1b72549454..df7557b874 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -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);
diff --git a/src/routes/debug.js b/src/routes/debug.js
index 6b413ee007..ab3258def3 100644
--- a/src/routes/debug.js
+++ b/src/routes/debug.js
@@ -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);
}
];
diff --git a/src/routes/user.js b/src/routes/user.js
index 80f97347a1..3eb0acd6b8 100644
--- a/src/routes/user.js
+++ b/src/routes/user.js
@@ -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;
diff --git a/src/sitemap.js b/src/sitemap.js
index b359b90d73..5568944297 100644
--- a/src/sitemap.js
+++ b/src/sitemap.js
@@ -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',
diff --git a/src/user.js b/src/user.js
index a7b8c95ca1..b45bf30275 100644
--- a/src/user.js
+++ b/src/user.js
@@ -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);
}
diff --git a/src/webserver.js b/src/webserver.js
index eac6204901..ad8614911d 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -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;