fix: saving teaserPid, timestamp, lastposttime in topic, fixed post index issue in loading topics

This commit is contained in:
Julian Lam
2024-01-17 12:15:58 -05:00
parent e038eb0509
commit 60bc27ec69
4 changed files with 12 additions and 6 deletions

View File

@@ -91,7 +91,7 @@ Notes.assertTopic = async (uid, id) => {
*/
const chain = Array.from(await Notes.getParentChain(uid, id));
const { pid: tid, uid: authorId } = chain[chain.length - 1];
const { pid: tid, uid: authorId, timestamp } = chain[chain.length - 1];
const members = await db.isSortedSetMembers(`tidRemote:${tid}:posts`, chain.map(p => p.pid));
if (members.every(Boolean)) {
@@ -118,6 +118,7 @@ Notes.assertTopic = async (uid, id) => {
mainPid: tid,
title: 'TBD',
slug: `remote?resource=${encodeURIComponent(tid)}`,
timestamp,
}),
db.sortedSetAdd(`tidRemote:${tid}:posts`, timestamps, ids),
Notes.assert(uid, unprocessed),
@@ -125,6 +126,8 @@ Notes.assertTopic = async (uid, id) => {
await Promise.all([ // must be done after .assert()
Notes.assertParentChain(chain),
Notes.updateTopicCounts(tid),
topics.updateLastPostTimeFromLastPid(tid),
topics.updateTeaser(tid),
]);
return tid;

View File

@@ -22,7 +22,7 @@ controller.get = async function (req, res, next) {
const tid = await notes.assertTopic(req.uid, req.query.resource);
let postIndex = await db.sortedSetRank(`tidRemote:${tid}:posts`, req.query.resource);
let postIndex = Math.max(1, await db.sortedSetRank(`tidRemote:${tid}:posts`, req.query.resource));
const [
userPrivileges,
settings,

View File

@@ -64,11 +64,13 @@ module.exports = function (Topics) {
};
Topics.setTopicField = async function (tid, field, value) {
await db.setObjectField(`topic:${tid}`, field, value);
const setPrefix = activitypub.helpers.isUri(tid) ? 'topicRemote' : 'topic';
await db.setObjectField(`${setPrefix}:${tid}`, field, value);
};
Topics.setTopicFields = async function (tid, data) {
await db.setObject(`topic:${tid}`, data);
const setPrefix = activitypub.helpers.isUri(tid) ? 'topicRemote' : 'topic';
await db.setObject(`${setPrefix}:${tid}`, data);
};
Topics.deleteTopicField = async function (tid, field) {

View File

@@ -231,15 +231,16 @@ module.exports = function (Topics) {
Topics.getLatestUndeletedReply = async function (tid) {
let isDeleted = false;
let index = 0;
const setPrefix = activitypub.helpers.isUri(tid) ? 'tidRemote' : 'tid';
do {
/* eslint-disable no-await-in-loop */
const pids = await db.getSortedSetRevRange(`tid:${tid}:posts`, index, index);
const pids = await db.getSortedSetRevRange(`${setPrefix}:${tid}:posts`, index, index);
if (!pids.length) {
return null;
}
isDeleted = await posts.getPostField(pids[0], 'deleted');
if (!isDeleted) {
return parseInt(pids[0], 10);
return pids[0];
}
index += 1;
} while (isDeleted);