more fixes

v1.18.x
Baris Soner Usakli 11 years ago
parent 2560704839
commit da626a4035

@ -656,6 +656,23 @@
}); });
} }
module.sortedSetRevRank = function(key, value, callback) {
if(value !== null && value !== undefined) {
value = value.toString();
}
module.getSortedSetRange(key, 0, -1, function(err, result) {
if(err) {
return callback(err);
}
var rank = result.indexOf(value);
if(rank === -1) {
return callback(null, null);
}
callback(null, result.length - rank - 1);
});
}
module.sortedSetScore = function(key, value, callback) { module.sortedSetScore = function(key, value, callback) {
if(value !== null && value !== undefined) { if(value !== null && value !== undefined) {
value = value.toString(); value = value.toString();

@ -382,6 +382,10 @@
redisClient.zrank(key, value, callback); redisClient.zrank(key, value, callback);
} }
module.sortedSetRevRank = function(key, value, callback) {
redisClient.zrevrank(key, value, callback);
}
module.sortedSetScore = function(key, value, callback) { module.sortedSetScore = function(key, value, callback) {
redisClient.zscore(key, value, callback); redisClient.zscore(key, value, callback);
} }

@ -245,7 +245,7 @@ var path = require('path'),
app.get('/recent/:term?', function (req, res, next) { app.get('/recent/:term?', function (req, res, next) {
var uid = (req.user) ? req.user.uid : 0; var uid = (req.user) ? req.user.uid : 0;
topics.getLatestTopics(uid, 0, 19, req.params.term, function (err, data) { topics.getLatestTopics(uid, 0, 9, req.params.term, function (err, data) {
if(err) { if(err) {
return next(err); return next(err);
} }

@ -426,8 +426,9 @@ var async = require('async'),
}; };
var since = terms['day']; var since = terms['day'];
if(terms[term]) if(terms[term]) {
since = terms[term]; since = terms[term];
}
var args = ['topics:recent', '+inf', timestamp - since, 'LIMIT', start, end - start + 1]; var args = ['topics:recent', '+inf', timestamp - since, 'LIMIT', start, end - start + 1];
db.getSortedSetRevRangeByScore(args, function(err, tids) { db.getSortedSetRevRangeByScore(args, function(err, tids) {
@ -442,11 +443,9 @@ var async = require('async'),
if (!tids || !tids.length) { if (!tids || !tids.length) {
latestTopics.no_topics_message = 'show'; latestTopics.no_topics_message = 'show';
callback(err, latestTopics); return callback(null, latestTopics);
return;
} }
// Filter out topics that belong to categories that this user cannot access
async.filter(tids, function(tid, next) { async.filter(tids, function(tid, next) {
threadTools.privileges(tid, current_user, function(err, privileges) { threadTools.privileges(tid, current_user, function(err, privileges) {
if (!err && privileges.read) { if (!err && privileges.read) {
@ -457,8 +456,20 @@ var async = require('async'),
}); });
}, function(tids) { }, function(tids) {
Topics.getTopicsByTids(tids, 0, current_user, function(err, topicData) { Topics.getTopicsByTids(tids, 0, current_user, function(err, topicData) {
latestTopics.topics = topicData; if(err) {
callback(err, latestTopics); return callback(err);
}
if(!topicData || !topicData.length) {
latestTopics.no_topics_message = 'show';
return callback(null, latestTopics);
}
db.sortedSetRevRank('topics:recent', topicData[topicData.length - 1].tid, function(err, rank) {
latestTopics.lastIndex = rank;
latestTopics.topics = topicData;
callback(null, latestTopics);
});
}); });
}); });
}); });
@ -700,6 +711,7 @@ var async = require('async'),
function isTopicVisible(topicData, topicInfo) { function isTopicVisible(topicData, topicInfo) {
var deleted = parseInt(topicData.deleted, 10) !== 0; var deleted = parseInt(topicData.deleted, 10) !== 0;
return !deleted || (deleted && topicInfo.privileges.view_deleted) || topicData.uid === current_user; return !deleted || (deleted && topicInfo.privileges.view_deleted) || topicData.uid === current_user;
} }
@ -738,7 +750,7 @@ var async = require('async'),
if (isTopicVisible(topicData, topicInfo)) { if (isTopicVisible(topicData, topicInfo)) {
retrieved_topics.push(topicData); retrieved_topics.push(topicData);
} } else console.log('not visible');
next(null); next(null);
}); });

Loading…
Cancel
Save