-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
45 lines (38 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function() {
"use strict";
var Categories = module.parent.require('./categories');
var db = module.parent.require('./database');
exports.filterTopicsPrepare = function(data, callback) {
var sets = typeof data.set === "string"? [data.set]: data.set;
Categories.getChildren([data.cid], data.uid, function(err, children) {
if(children && children[0]) {
children[0].forEach(function(child) {
sets.push("cid:" + child.cid + ":tids");
});
}
data.set = [ { unionArray: sets } ];
return callback(null, data);
});
};
exports.init = function init(params, callback) {
var orig_getSortedSetRevIntersect = db.getSortedSetRevIntersect;
db.getSortedSetRevIntersect = function(params, callback) {
var sets = params.sets;
if(Array.isArray(sets) && sets[0] && sets[0].unionArray) {
return db.getSortedSetRevRange(sets[0].unionArray, params.start, params.stop, callback);
} else {
return orig_getSortedSetRevIntersect.apply(this, arguments);
}
};
var orig_getSortedSetIntersect = db.getSortedSetIntersect;
db.getSortedSetIntersect = function(params, callback) {
var sets = params.sets;
if(Array.isArray(sets) && sets[0] && sets[0].unionArray) {
return db.getSortedSetRange(sets[0].unionArray, params.start, params.stop, callback);
} else {
return orig_getSortedSetIntersect.apply(this, arguments);
}
};
return callback();
};
})();