cache categories:cid and cid:<cid>:children

these rarely change, no need to go to db for them
This commit is contained in:
Barış Soner Uşaklı
2018-11-27 19:38:28 -05:00
parent 7357926fe7
commit 00a066985a
15 changed files with 168 additions and 43 deletions

View File

@@ -14,9 +14,6 @@ module.exports = function (User) {
};
User.getWatchedCategories = function (uid, callback) {
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, []);
}
async.waterfall([
function (next) {
async.parallel({
@@ -24,16 +21,13 @@ module.exports = function (User) {
User.getIgnoredCategories(uid, next);
},
all: function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
categories.getAllCidsFromSet('categories:cid', next);
},
}, next);
},
function (results, next) {
const ignored = new Set(results.ignored);
var watched = results.all.filter(function (cid) {
return cid && !ignored.has(String(cid));
});
const watched = results.all.filter(cid => cid && !ignored.has(String(cid)));
next(null, watched);
},
], callback);