mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 03:01:08 +01:00
Merge branch 'master' of github.com:psychobunny/node-forum
This commit is contained in:
@@ -154,7 +154,7 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
jQuery.get(API_URL + api_url, function(data) {
|
jQuery.get(API_URL + api_url, function(data) {
|
||||||
if(data === false) {
|
if(!data) {
|
||||||
ajaxify.go('404');
|
ajaxify.go('404');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
63
src/routes/testbed.js
Normal file
63
src/routes/testbed.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
|
||||||
|
(function(TestBed) {
|
||||||
|
TestBed.create_routes = function(app) {
|
||||||
|
|
||||||
|
app.get('/bench/forloop', function(req, res) {
|
||||||
|
var benchData = {};
|
||||||
|
|
||||||
|
var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||||
|
|
||||||
|
function f(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
var runCount = req.query.runs ? req.query.runs : 1000000;
|
||||||
|
|
||||||
|
function withCaching() {
|
||||||
|
var time = process.hrtime();
|
||||||
|
|
||||||
|
for(var n=0; n<runCount; ++n) {
|
||||||
|
for (var i = 0, len = myArray.length; i < len; ++i) {
|
||||||
|
f(myArray[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var diff = process.hrtime(time);
|
||||||
|
diff = diff[0] + diff[1] / 1e9;
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withoutCaching() {
|
||||||
|
var time = process.hrtime();
|
||||||
|
|
||||||
|
for(var n=0; n<runCount; ++n) {
|
||||||
|
for (var i = 0; i < myArray.length; ++i) {
|
||||||
|
f(myArray[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var diff = process.hrtime(time);
|
||||||
|
diff = diff[0] + diff[1] / 1e9;
|
||||||
|
return diff;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
benchData['runs'] = runCount;
|
||||||
|
|
||||||
|
benchData['withCaching'] = withCaching();
|
||||||
|
benchData['withoutCaching'] = withoutCaching();
|
||||||
|
|
||||||
|
res.json(benchData);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}(exports));
|
||||||
@@ -259,22 +259,10 @@ var user = require('./../user.js'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(String(req.params.section).toLowerCase() === 'following') {
|
else if(String(req.params.section).toLowerCase() === 'following') {
|
||||||
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
|
getFollowing(req, res, callerUID);
|
||||||
user.getFollowing(userData.uid, function(followingData){
|
|
||||||
userData.following = followingData;
|
|
||||||
userData.followingCount = followingData.length;
|
|
||||||
res.json(userData);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else if(String(req.params.section).toLowerCase() === 'followers') {
|
else if(String(req.params.section).toLowerCase() === 'followers') {
|
||||||
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
|
getFollowers(req, res, callerUID);
|
||||||
user.getFollowers(userData.uid, function(followersData){
|
|
||||||
userData.followers = followersData;
|
|
||||||
userData.followersCount = followersData.length;
|
|
||||||
res.json(userData);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else if (String(req.params.section).toLowerCase() === 'edit') {
|
else if (String(req.params.section).toLowerCase() === 'edit') {
|
||||||
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
|
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
|
||||||
@@ -295,6 +283,35 @@ var user = require('./../user.js'),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFollowing(req, res, callerUid) {
|
||||||
|
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
|
||||||
|
if(userData) {
|
||||||
|
user.getFollowing(userData.uid, function(followingData){
|
||||||
|
userData.following = followingData;
|
||||||
|
userData.followingCount = followingData.length;
|
||||||
|
res.json(userData);
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
res.json(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFollowers(req, res, callerUid) {
|
||||||
|
getUserDataByUserSlug(req.params.userslug, callerUid, function(userData) {
|
||||||
|
if(userData) {
|
||||||
|
user.getFollowers(userData.uid, function(followersData){
|
||||||
|
userData.followers = followersData;
|
||||||
|
userData.followersCount = followersData.length;
|
||||||
|
res.json(userData);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.json(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
app.get('/api/users/:userslug?/:section?', api_method);
|
app.get('/api/users/:userslug?/:section?', api_method);
|
||||||
app.get('/api/users-sort-posts', getUsersSortedByPosts);
|
app.get('/api/users-sort-posts', getUsersSortedByPosts);
|
||||||
app.get('/api/users-sort-reputation', getUsersSortedByReputation);
|
app.get('/api/users-sort-reputation', getUsersSortedByReputation);
|
||||||
@@ -332,9 +349,14 @@ var user = require('./../user.js'),
|
|||||||
res.json({ search_display: 'block', users: [] });
|
res.json({ search_display: 'block', users: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getUserDataByUserSlug(userslug, callerUID, callback) {
|
function getUserDataByUserSlug(userslug, callerUID, callback) {
|
||||||
user.get_uid_by_userslug(userslug, function(uid) {
|
user.get_uid_by_userslug(userslug, function(uid) {
|
||||||
|
|
||||||
|
if(uid === null) {
|
||||||
|
callback(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
user.getUserData(uid, function(data) {
|
user.getUserData(uid, function(data) {
|
||||||
if(data) {
|
if(data) {
|
||||||
data.joindate = utils.relativeTime(data.joindate);
|
data.joindate = utils.relativeTime(data.joindate);
|
||||||
@@ -357,8 +379,7 @@ var user = require('./../user.js'),
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// @todo why is this an empty object? perhaps the callback should expect NULL or undefined instead.
|
callback(null);
|
||||||
callback({});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ var express = require('express'),
|
|||||||
admin = require('./routes/admin.js'),
|
admin = require('./routes/admin.js'),
|
||||||
userRoute = require('./routes/user.js'),
|
userRoute = require('./routes/user.js'),
|
||||||
installRoute = require('./routes/install.js'),
|
installRoute = require('./routes/install.js'),
|
||||||
|
testBed = require('./routes/testbed.js'),
|
||||||
auth = require('./routes/authentication.js'),
|
auth = require('./routes/authentication.js'),
|
||||||
meta = require('./meta.js');
|
meta = require('./meta.js');
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ var express = require('express'),
|
|||||||
admin.create_routes(app);
|
admin.create_routes(app);
|
||||||
userRoute.create_routes(app);
|
userRoute.create_routes(app);
|
||||||
installRoute.create_routes(app);
|
installRoute.create_routes(app);
|
||||||
|
testBed.create_routes(app);
|
||||||
|
|
||||||
app.create_route = function(url, tpl) { // to remove
|
app.create_route = function(url, tpl) { // to remove
|
||||||
return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';
|
return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';
|
||||||
|
|||||||
Reference in New Issue
Block a user