feat: small fixes

v1.18.x
Barış Soner Uşaklı 6 years ago
parent b2a74b4172
commit fef7e13c9e

@ -290,7 +290,10 @@ module.exports = function (db, module) {
module.sortedSetScores = function (key, values, callback) {
if (!key) {
return callback(null, null);
return setImmediate(callback, null, null);
}
if (!values.length) {
return setImmediate(callback, null, []);
}
values = values.map(helpers.valueToString);
db.collection('objects').find({ _key: key, value: { $in: values } }, { projection: { _id: 0, _key: 0 } }).toArray(function (err, result) {

@ -382,9 +382,11 @@ SELECT o."_key" k,
module.sortedSetScores = function (key, values, callback) {
if (!key) {
return callback(null, null);
return setImmediate(callback, null, null);
}
if (!values.length) {
return setImmediate(callback, null, []);
}
values = values.map(helpers.valueToString);
query({

@ -185,6 +185,9 @@ module.exports = function (redisClient, module) {
};
module.sortedSetScores = function (key, values, callback) {
if (!values.length) {
return setImmediate(callback, null, []);
}
helpers.execKeyValues(redisClient, 'batch', 'zscore', key, values, function (err, scores) {
if (err) {
return callback(err);

@ -86,12 +86,7 @@ module.exports = function (Posts) {
Posts.hasBookmarked = function (pid, uid, callback) {
if (parseInt(uid, 10) <= 0) {
if (Array.isArray(pid)) {
callback(null, pid.map(() => false));
} else {
callback(null, false);
}
return;
return callback(null, Array.isArray(pid) ? pid.map(() => false) : false);
}
if (Array.isArray(pid)) {

@ -188,13 +188,15 @@ Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse,
topicData.bookmark = results.bookmark;
topicData.postSharing = results.postSharing;
topicData.deleter = results.deleter;
topicData.deletedTimestampISO = utils.toISOString(topicData.deletedTimestamp);
if (results.deleter) {
topicData.deletedTimestampISO = utils.toISOString(topicData.deletedTimestamp);
}
topicData.merger = results.merger;
topicData.mergedTimestampISO = utils.toISOString(topicData.mergedTimestamp);
if (results.merger) {
topicData.mergedTimestampISO = utils.toISOString(topicData.mergedTimestamp);
}
topicData.related = results.related || [];
topicData.unreplied = topicData.postcount === 1;
topicData.icons = [];
plugins.fireHook('filter:topic.get', { topic: topicData, uid: uid }, next);
@ -245,14 +247,14 @@ function getMainPostAndReplies(topic, set, uid, start, stop, reverse, callback)
}
function getDeleter(topicData, callback) {
if (!topicData.deleterUid) {
if (!parseInt(topicData.deleterUid, 10)) {
return setImmediate(callback, null, null);
}
user.getUserFields(topicData.deleterUid, ['username', 'userslug', 'picture'], callback);
}
function getMerger(topicData, callback) {
if (!topicData.mergerUid) {
if (!parseInt(topicData.mergerUid, 10)) {
return setImmediate(callback, null, null);
}
async.waterfall([

@ -154,7 +154,7 @@ module.exports = function (Topics) {
if (!parentPids.length) {
return setImmediate(callback);
}
parentPids = _.uniq(parentPids);
var parentPosts;
async.waterfall([
async.apply(posts.getPostsFields, parentPids, ['uid']),

@ -232,13 +232,13 @@ module.exports = function (Topics) {
};
Topics.getTagData = function (tags, callback) {
var keys = tags.map(function (tag) {
return 'tag:' + tag.value;
});
if (!tags.length) {
return setImmediate(callback, null, []);
}
async.waterfall([
function (next) {
db.getObjects(keys, next);
db.getObjects(tags.map(tag => 'tag:' + tag.value), next);
},
function (tagData, next) {
tags.forEach(function (tag, index) {

@ -581,6 +581,15 @@ describe('Sorted Set methods', function () {
});
});
it('should return empty array if values is an empty array', function (done) {
db.sortedSetScores('sortedSetTest1', [], function (err, scores) {
assert.ifError(err);
assert.equal(arguments.length, 2);
assert.deepStrictEqual(scores, []);
done();
});
});
it('should return scores properly', function (done) {
db.sortedSetsScore(['zeroScore', 'sortedSetTest1', 'doesnotexist'], 'value1', function (err, scores) {
assert.ifError(err);

Loading…
Cancel
Save