Category watch state (#7109)

* feat: wip, category watch change

* feat: pass data to client

* feat: allow changing state

* fix: account page categories

* fix: show in unread if topic is followed or category is watched

* feat: add default watch state to acp

* feat: save user category watch state

* feat: update unread recent pages

* fix: remove dupe code

* fix: flip conditions

* fix: handle empty arrays

* fix: ignore/watch on others profile

* feat: upgrade script for category states

if there are any users ignoring categories set their state in new zset and delete cid:<cid>:ignorers

* fix: upgrade

* fix: tests

* fix: redis count

* fix: more tests
This commit is contained in:
Barış Soner Uşaklı
2018-12-14 16:24:17 -05:00
committed by GitHub
parent 2104877c76
commit eb7ae54f81
28 changed files with 376 additions and 136 deletions

View File

@@ -56,6 +56,10 @@ module.exports = function (db, module) {
query.score.$lte = max;
}
if (max === min) {
query.score = max;
}
const fields = { _id: 0, _key: 0 };
if (!withScores) {
fields.score = 0;
@@ -115,10 +119,12 @@ module.exports = function (db, module) {
};
function getSortedSetRangeByScore(key, start, count, min, max, sort, withScores, callback) {
if (parseInt(count, 10) === -1) {
count = 0;
if (parseInt(count, 10) === 0) {
return setImmediate(callback, null, []);
}
var stop = start + count - 1;
const stop = (parseInt(count, 10) === -1) ? -1 : (start + count - 1);
console.log(key, start, stop);
getSortedSetRange(key, start, stop, min, max, sort, withScores, callback);
}
@@ -261,7 +267,7 @@ module.exports = function (db, module) {
module.sortedSetsScore = function (keys, value, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback();
return callback(null, []);
}
value = helpers.valueToString(value);
db.collection('objects').find({ _key: { $in: keys }, value: value }, { projection: { _id: 0, value: 0 } }).toArray(function (err, result) {

View File

@@ -348,7 +348,7 @@ SELECT z."score" s
module.sortedSetsScore = function (keys, value, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback();
return callback(null, []);
}
value = helpers.valueToString(value);

View File

@@ -170,6 +170,9 @@ module.exports = function (redisClient, module) {
};
module.sortedSetsScore = function (keys, value, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, []);
}
helpers.execKeysValue(redisClient, 'batch', 'zscore', keys, value, function (err, scores) {
if (err) {
return callback(err);