How to improve popular posts response time?
Solved
Technical Support
-
It would look something like this
myPlugin.actionTopicReply = async function (hookData) { const userGroups = await Groups.getUserGroupMembership('groups:visible:createtime', [hookData.data.uid]); const isInDevGroup = userGroups.flat().includes('My developer group'); if (isInDevGroup) { await topics.setTopicField(hookData.topic.tid, 'postedInByDeveloper', 1); } };
So essentially you save a field into the topic object if a developer posts in it. This way you don't need to calculate it each time the topic list is loaded.
-
You might want to use both
action:topic.reply
andaction:topic.post
one is triggered on reply and one is triggered when a new topic is posted. Also if the developer group is visible then you can useconst userGroups = await Groups.getUserGroupMembership('groups:visible:createtime', [hookData.data.uid]);
and it will be even faster. -
-
I just realized there is a much simpler way to do this, since you only seem to care about if the user is in a special
dev group
you don't need to load the user's groups, you can just check if they are in that special group.myPlugin.actionTopicReply = async function (hookData) { const isInDevGroup = await Groups.isMember(hookData.data.uid, 'My developer group'); if (isInDevGroup) { await topics.setTopicField(hookData.topic.tid, 'postedInByDeveloper', 1); } };
Copyright © 2024 NodeBB | Contributors