Skip to content

Node.js based forum software built for the modern web

fix: check if unread_tids are followed

Barış Soner Uşaklı2d5bd153e072
diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js
index 7bacae999f..e5580ecc93 100644
--- a/src/database/mongo/sorted.js
+++ b/src/database/mongo/sorted.js
@@ -318,6 +318,9 @@ module.exports = function (module) {
if (!key) {
return;
}
+ if (!values.length) {
+ return [];
+ }
values = values.map(helpers.valueToString);
const results = await module.client.collection('objects').find({
_key: key, value: { $in: values },
diff --git a/src/database/postgres/sorted.js b/src/database/postgres/sorted.js
index f9a53706f8..bb1af3d291 100644
--- a/src/database/postgres/sorted.js
+++ b/src/database/postgres/sorted.js
@@ -410,6 +410,9 @@ SELECT 1
return;
}
+ if (!values.length) {
+ return [];
+ }
values = values.map(helpers.valueToString);
const res = await module.pool.query({
diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js
index 0002e38c08..5540c7e5b7 100644
--- a/src/database/redis/sorted.js
+++ b/src/database/redis/sorted.js
@@ -203,6 +203,9 @@ module.exports = function (module) {
};
module.isSortedSetMembers = async function (key, values) {
+ if (!values.length) {
+ return [];
+ }
const batch = module.client.batch();
values.forEach(v => batch.zscore(key, String(v)));
const results = await helpers.execBatch(batch);
diff --git a/src/topics/unread.js b/src/topics/unread.js
index cac378142b..e8ed36a2a9 100644
--- a/src/topics/unread.js
+++ b/src/topics/unread.js
@@ -101,10 +101,21 @@ module.exports = function (Topics) {
]);
const userReadTime = _.mapValues(_.keyBy(userScores, 'value'), 'score');
- const isTopicsFollowed = _.mapValues(_.keyBy(followedTids, 'value'), 'score');
+ const isTopicsFollowed = {};
+ followedTids.forEach((t) => {
+ isTopicsFollowed[t.value] = true;
+ });
+ const unreadFollowed = await db.isSortedSetMembers(
+ 'uid:' + params.uid + ':followed_tids', tids_unread.map(t => t.value)
+ );
+
+ tids_unread.forEach((t, i) => {
+ isTopicsFollowed[t.value] = unreadFollowed[i];
+ });
- const unreadTopics = _.unionWith(categoryTids, followedTids.concat(tids_unread), (a, b) => a.value === b.value)
+ const unreadTopics = _.unionWith(categoryTids, followedTids, (a, b) => a.value === b.value)
.filter(t => !ignoredTids.includes(t.value) && (!userReadTime[t.value] || t.score > userReadTime[t.value]))
+ .concat(tids_unread)
.sort((a, b) => b.score - a.score);
let tids = _.uniq(unreadTopics.map(topic => topic.value)).slice(0, 200);