fix: #7788 No new posts (#7793)

* feat: debug no-new-posts

* feat: add test for user delete

* fix: timeout for flag test

* feat: shorter
v1.18.x
Barış Soner Uşaklı 6 years ago committed by GitHub
parent e76214a25c
commit 3c32d8600f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,7 +29,8 @@ module.exports = function (Categories) {
return await db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid);
}
const data = await db.getSortedSetRangeWithScores('cid:' + cid + ':recent_tids', 0, count - numRecentReplies);
if (data.length) {
const shouldRemove = !(data.length === 1 && count === 1 && data[0].value === String(tid));
if (data.length && shouldRemove) {
await db.sortedSetsRemoveRangeByScore(['cid:' + cid + ':recent_tids'], '-inf', data[data.length - 1].score);
}
await db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid);

@ -36,6 +36,7 @@ module.exports = function (Posts) {
db.sortedSetRemove('cid:' + topicData.cid + ':pids', pid) :
db.sortedSetAdd('cid:' + topicData.cid + ':pids', postData.timestamp, pid),
]);
await categories.updateRecentTidForCid(postData.cid);
plugins.fireHook('action:post.' + type, { post: _.clone(postData), uid: uid });
return postData;
}
@ -45,11 +46,12 @@ module.exports = function (Posts) {
if (!postData) {
return;
}
const topicData = await topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned']);
postData.cid = topicData.cid;
await plugins.fireHook('filter:post.purge', { post: postData, pid: pid, uid: uid });
await Promise.all([
deletePostFromTopicUserNotification(postData),
deletePostFromCategoryRecentPosts(pid),
deletePostFromTopicUserNotification(postData, topicData),
deletePostFromCategoryRecentPosts(postData),
deletePostFromUsersBookmarks(pid),
deletePostFromUsersVotes(pid),
deletePostFromReplies(postData),
@ -60,13 +62,13 @@ module.exports = function (Posts) {
await db.delete('post:' + pid);
};
async function deletePostFromTopicUserNotification(postData) {
async function deletePostFromTopicUserNotification(postData, topicData) {
await db.sortedSetsRemove([
'tid:' + postData.tid + ':posts',
'tid:' + postData.tid + ':posts:votes',
'uid:' + postData.uid + ':posts',
], postData.pid);
const topicData = await topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned']);
const tasks = [
db.decrObjectField('global', 'postCount'),
db.decrObjectField('category:' + topicData.cid, 'post_count'),
@ -79,16 +81,18 @@ module.exports = function (Posts) {
user.incrementUserPostCountBy(postData.uid, -1),
notifications.rescind('new_post:tid:' + postData.tid + ':pid:' + postData.pid + ':uid:' + postData.uid),
];
if (!topicData.pinned) {
tasks.push(db.sortedSetIncrBy, 'cid:' + topicData.cid + ':tids:posts', -1, postData.tid);
tasks.push(db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid));
}
await Promise.all(tasks);
}
async function deletePostFromCategoryRecentPosts(pid) {
async function deletePostFromCategoryRecentPosts(postData) {
const cids = await categories.getAllCidsFromSet('categories:cid');
const sets = cids.map(cid => 'cid:' + cid + ':pids');
await db.sortedSetsRemove(sets, pid);
await db.sortedSetsRemove(sets, postData.pid);
await categories.updateRecentTidForCid(postData.cid);
}
async function deletePostFromUsersBookmarks(pid) {

@ -5,6 +5,7 @@ var db = require('../database');
var user = require('../user');
var posts = require('../posts');
const categories = require('../categories');
var plugins = require('../plugins');
var batch = require('../batch');
@ -33,6 +34,7 @@ module.exports = function (Topics) {
Topics.getPids(tid),
]);
await db.sortedSetRemove('cid:' + cid + ':pids', pids);
await categories.updateRecentTidForCid(cid);
}
async function addTopicPidsToCid(tid) {
@ -49,6 +51,7 @@ module.exports = function (Topics) {
scores.push(post.timestamp);
});
await db.sortedSetAdd('cid:' + cid + ':pids', scores, pidsToAdd);
await categories.updateRecentTidForCid(cid);
}
Topics.restore = async function (tid) {
@ -137,6 +140,7 @@ module.exports = function (Topics) {
], tid),
user.decrementUserFieldBy(topicData.uid, 'topiccount', 1),
]);
await categories.updateRecentTidForCid(topicData.cid);
}
async function reduceCounters(tid) {

@ -43,7 +43,6 @@ module.exports = function (Topics) {
} else {
await Topics.restore(tid);
}
await categories.updateRecentTidForCid(topicData.cid);
topicData.deleted = isDelete ? 1 : 0;

@ -449,7 +449,7 @@ describe('Flags', function () {
}
assert.strictEqual('[1,"this is my note"]', notes[0]);
done();
setTimeout(done, 10);
});
});
});

@ -73,6 +73,37 @@ describe('Post\'s', function () {
});
});
it('should update category teaser properly', async function () {
const util = require('util');
const getCategoriesAsync = util.promisify(async function getCategories(callback) {
request(nconf.get('url') + '/api/categories', { json: true }, function (err, res, body) {
callback(err, body);
});
});
const postResult = await topics.post({ uid: globalModUid, cid: cid, title: 'topic title', content: '123456789' });
let data = await getCategoriesAsync();
assert.equal(data.categories[0].teaser.pid, postResult.postData.pid);
assert.equal(data.categories[0].posts[0].content, '123456789');
assert.equal(data.categories[0].posts[0].pid, postResult.postData.pid);
const newUid = await user.create({ username: 'teaserdelete' });
const newPostResult = await topics.post({ uid: newUid, cid: cid, title: 'topic title', content: 'xxxxxxxx' });
data = await getCategoriesAsync();
assert.equal(data.categories[0].teaser.pid, newPostResult.postData.pid);
assert.equal(data.categories[0].posts[0].content, 'xxxxxxxx');
assert.equal(data.categories[0].posts[0].pid, newPostResult.postData.pid);
await user.delete(1, newUid);
data = await getCategoriesAsync();
assert.equal(data.categories[0].teaser.pid, postResult.postData.pid);
assert.equal(data.categories[0].posts[0].content, '123456789');
assert.equal(data.categories[0].posts[0].pid, postResult.postData.pid);
});
it('should change owner of post and topic properly', async function () {
const oldUid = await user.create({ username: 'olduser' });
const newUid = await user.create({ username: 'newuser' });

Loading…
Cancel
Save