mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
simplified getAllTopics
This commit is contained in:
@@ -332,7 +332,7 @@ var nconf = require('nconf'),
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/topics', function (req, res) {
|
app.get('/topics', function (req, res) {
|
||||||
topics.getAllTopics(10, null, function (err, topics) {
|
topics.getAllTopics(0, 19, function (err, topics) {
|
||||||
res.json({
|
res.json({
|
||||||
topics: topics,
|
topics: topics,
|
||||||
notopics: topics.length === 0
|
notopics: topics.length === 0
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ var path = require('path'),
|
|||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
var topicUrls = [];
|
var topicUrls = [];
|
||||||
topics.getAllTopics(null, null, function(err, topics) {
|
topics.getAllTopics(0, -1, function(err, topics) {
|
||||||
topics.forEach(function(topic) {
|
topics.forEach(function(topic) {
|
||||||
|
|
||||||
if (parseInt(topic.deleted, 10) !== 1) {
|
if (parseInt(topic.deleted, 10) !== 1) {
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ SocketAdmin.topics.getMore = function(socket, data, callback) {
|
|||||||
return callback(new Error('invalid data'));
|
return callback(new Error('invalid data'));
|
||||||
}
|
}
|
||||||
|
|
||||||
topics.getAllTopics(data.limit, data.after, callback);
|
var start = parseInt(data.after, 10),
|
||||||
|
end = start + parseInt(data.limit, 10);
|
||||||
|
|
||||||
|
topics.getAllTopics(start, end, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* User */
|
/* User */
|
||||||
|
|||||||
@@ -424,12 +424,12 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
function getTopics(set, uid, tids, callback) {
|
function getTopics(set, uid, tids, callback) {
|
||||||
var latestTopics = {
|
var returnTopics = {
|
||||||
'topics': []
|
'topics': []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!tids || !tids.length) {
|
if (!tids || !tids.length) {
|
||||||
return callback(null, latestTopics);
|
return callback(null, returnTopics);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.filter(tids, function(tid, next) {
|
async.filter(tids, function(tid, next) {
|
||||||
@@ -443,7 +443,7 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!topicData || !topicData.length) {
|
if(!topicData || !topicData.length) {
|
||||||
return callback(null, latestTopics);
|
return callback(null, returnTopics);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.sortedSetRevRank(set, topicData[topicData.length - 1].tid, function(err, rank) {
|
db.sortedSetRevRank(set, topicData[topicData.length - 1].tid, function(err, rank) {
|
||||||
@@ -451,9 +451,9 @@ var async = require('async'),
|
|||||||
return calllback(err);
|
return calllback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
latestTopics.nextStart = parseInt(rank, 10) + 1;
|
returnTopics.nextStart = parseInt(rank, 10) + 1;
|
||||||
latestTopics.topics = topicData;
|
returnTopics.topics = topicData;
|
||||||
callback(null, latestTopics);
|
callback(null, returnTopics);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -905,49 +905,11 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getAllTopics = function(limit, after, callback) {
|
Topics.getAllTopics = function(start, end, callback) {
|
||||||
db.getSetMembers('topics:tid', function(err, tids) {
|
db.getSortedSetRevRange('topics:recent', start, end, function(err, tids) {
|
||||||
if(err) {
|
async.map(tids, function(tid, next) {
|
||||||
return callback(err, null);
|
Topics.getTopicDataWithUser(tid, next);
|
||||||
}
|
}, callback);
|
||||||
|
|
||||||
var topics = [],
|
|
||||||
numTids, x;
|
|
||||||
|
|
||||||
// Sort into ascending order
|
|
||||||
tids.sort(function(a, b) {
|
|
||||||
return a - b;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Eliminate everything after the "after" tid
|
|
||||||
if (after) {
|
|
||||||
for (x = 0, numTids = tids.length; x < numTids; x++) {
|
|
||||||
if (tids[x] >= after) {
|
|
||||||
tids = tids.slice(0, x);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (limit) {
|
|
||||||
if (limit > 0 && limit < tids.length) {
|
|
||||||
tids = tids.slice(tids.length - limit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort into descending order
|
|
||||||
tids.sort(function(a, b) {
|
|
||||||
return b - a;
|
|
||||||
});
|
|
||||||
|
|
||||||
async.each(tids, function(tid, next) {
|
|
||||||
Topics.getTopicDataWithUser(tid, function(err, topicData) {
|
|
||||||
topics.push(topicData);
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}, function(err) {
|
|
||||||
callback(err, topics);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user