mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 18:56:15 +01:00
* feat: debug no-new-posts * feat: add test for user delete * fix: timeout for flag test * feat: shorter
This commit is contained in:
committed by
GitHub
parent
e76214a25c
commit
3c32d8600f
@@ -29,7 +29,8 @@ module.exports = function (Categories) {
|
|||||||
return await db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid);
|
return await db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid);
|
||||||
}
|
}
|
||||||
const data = await db.getSortedSetRangeWithScores('cid:' + cid + ':recent_tids', 0, count - numRecentReplies);
|
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.sortedSetsRemoveRangeByScore(['cid:' + cid + ':recent_tids'], '-inf', data[data.length - 1].score);
|
||||||
}
|
}
|
||||||
await db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid);
|
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.sortedSetRemove('cid:' + topicData.cid + ':pids', pid) :
|
||||||
db.sortedSetAdd('cid:' + topicData.cid + ':pids', postData.timestamp, 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 });
|
plugins.fireHook('action:post.' + type, { post: _.clone(postData), uid: uid });
|
||||||
return postData;
|
return postData;
|
||||||
}
|
}
|
||||||
@@ -45,11 +46,12 @@ module.exports = function (Posts) {
|
|||||||
if (!postData) {
|
if (!postData) {
|
||||||
return;
|
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 plugins.fireHook('filter:post.purge', { post: postData, pid: pid, uid: uid });
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
deletePostFromTopicUserNotification(postData),
|
deletePostFromTopicUserNotification(postData, topicData),
|
||||||
deletePostFromCategoryRecentPosts(pid),
|
deletePostFromCategoryRecentPosts(postData),
|
||||||
deletePostFromUsersBookmarks(pid),
|
deletePostFromUsersBookmarks(pid),
|
||||||
deletePostFromUsersVotes(pid),
|
deletePostFromUsersVotes(pid),
|
||||||
deletePostFromReplies(postData),
|
deletePostFromReplies(postData),
|
||||||
@@ -60,13 +62,13 @@ module.exports = function (Posts) {
|
|||||||
await db.delete('post:' + pid);
|
await db.delete('post:' + pid);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function deletePostFromTopicUserNotification(postData) {
|
async function deletePostFromTopicUserNotification(postData, topicData) {
|
||||||
await db.sortedSetsRemove([
|
await db.sortedSetsRemove([
|
||||||
'tid:' + postData.tid + ':posts',
|
'tid:' + postData.tid + ':posts',
|
||||||
'tid:' + postData.tid + ':posts:votes',
|
'tid:' + postData.tid + ':posts:votes',
|
||||||
'uid:' + postData.uid + ':posts',
|
'uid:' + postData.uid + ':posts',
|
||||||
], postData.pid);
|
], postData.pid);
|
||||||
const topicData = await topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned']);
|
|
||||||
const tasks = [
|
const tasks = [
|
||||||
db.decrObjectField('global', 'postCount'),
|
db.decrObjectField('global', 'postCount'),
|
||||||
db.decrObjectField('category:' + topicData.cid, 'post_count'),
|
db.decrObjectField('category:' + topicData.cid, 'post_count'),
|
||||||
@@ -79,16 +81,18 @@ module.exports = function (Posts) {
|
|||||||
user.incrementUserPostCountBy(postData.uid, -1),
|
user.incrementUserPostCountBy(postData.uid, -1),
|
||||||
notifications.rescind('new_post:tid:' + postData.tid + ':pid:' + postData.pid + ':uid:' + postData.uid),
|
notifications.rescind('new_post:tid:' + postData.tid + ':pid:' + postData.pid + ':uid:' + postData.uid),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!topicData.pinned) {
|
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);
|
await Promise.all(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deletePostFromCategoryRecentPosts(pid) {
|
async function deletePostFromCategoryRecentPosts(postData) {
|
||||||
const cids = await categories.getAllCidsFromSet('categories:cid');
|
const cids = await categories.getAllCidsFromSet('categories:cid');
|
||||||
const sets = cids.map(cid => 'cid:' + cid + ':pids');
|
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) {
|
async function deletePostFromUsersBookmarks(pid) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ var db = require('../database');
|
|||||||
|
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var posts = require('../posts');
|
var posts = require('../posts');
|
||||||
|
const categories = require('../categories');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var batch = require('../batch');
|
var batch = require('../batch');
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ module.exports = function (Topics) {
|
|||||||
Topics.getPids(tid),
|
Topics.getPids(tid),
|
||||||
]);
|
]);
|
||||||
await db.sortedSetRemove('cid:' + cid + ':pids', pids);
|
await db.sortedSetRemove('cid:' + cid + ':pids', pids);
|
||||||
|
await categories.updateRecentTidForCid(cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addTopicPidsToCid(tid) {
|
async function addTopicPidsToCid(tid) {
|
||||||
@@ -49,6 +51,7 @@ module.exports = function (Topics) {
|
|||||||
scores.push(post.timestamp);
|
scores.push(post.timestamp);
|
||||||
});
|
});
|
||||||
await db.sortedSetAdd('cid:' + cid + ':pids', scores, pidsToAdd);
|
await db.sortedSetAdd('cid:' + cid + ':pids', scores, pidsToAdd);
|
||||||
|
await categories.updateRecentTidForCid(cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.restore = async function (tid) {
|
Topics.restore = async function (tid) {
|
||||||
@@ -137,6 +140,7 @@ module.exports = function (Topics) {
|
|||||||
], tid),
|
], tid),
|
||||||
user.decrementUserFieldBy(topicData.uid, 'topiccount', 1),
|
user.decrementUserFieldBy(topicData.uid, 'topiccount', 1),
|
||||||
]);
|
]);
|
||||||
|
await categories.updateRecentTidForCid(topicData.cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function reduceCounters(tid) {
|
async function reduceCounters(tid) {
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ module.exports = function (Topics) {
|
|||||||
} else {
|
} else {
|
||||||
await Topics.restore(tid);
|
await Topics.restore(tid);
|
||||||
}
|
}
|
||||||
await categories.updateRecentTidForCid(topicData.cid);
|
|
||||||
|
|
||||||
topicData.deleted = isDelete ? 1 : 0;
|
topicData.deleted = isDelete ? 1 : 0;
|
||||||
|
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ describe('Flags', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert.strictEqual('[1,"this is my note"]', notes[0]);
|
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 () {
|
it('should change owner of post and topic properly', async function () {
|
||||||
const oldUid = await user.create({ username: 'olduser' });
|
const oldUid = await user.create({ username: 'olduser' });
|
||||||
const newUid = await user.create({ username: 'newuser' });
|
const newUid = await user.create({ username: 'newuser' });
|
||||||
|
|||||||
Reference in New Issue
Block a user