Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.14.4] Threads always ignored when a channel overrides overrides the global retention policy #22384

Closed
NickstaDB opened this issue Jun 17, 2021 · 3 comments · Fixed by #32485

Comments

@NickstaDB
Copy link

Description:

When a channel is configured to override the global retention policy, there is no option to set the "Do not prune Threads" option within the channel's own retention policy, and no default value is set for the Room.retention.ignoreThreads setting, therefore threads are always ignored during message pruning on a channel that overrides the global retention policy.

Steps to reproduce:

  1. Enable the retention policy at /admin/RetentionPolicy and ensure that the global policy does not apply to channels
  2. Open the Room information panel within a channel (e.g. /channel/general/channel-settings)
  3. Click Edit and enable Automatically prune old messages and Override global retention policy
  4. Observe that there is no Do not prune Threads option
  5. Post a message to the channel, then reply to the message in order to create a thread
  6. Update the message timestamps (ts field in the MongoDB documents), so that they are older than the configured maximum age
  7. Trigger message pruning
  8. Observe that the thread is not deleted, despite being older than the configured maximum age

Expected behavior:

  1. There should be an option to configure the Do not prune threads retention policy setting on a per-channel basis
  2. When the Do not prune Threads setting is disabled, threaded messages that are older than the maximum age should be deleted when the message pruning task runs

Actual behavior:

  1. There is no option to configure the Do not prune threads retention policy setting on a per-channel basis
  2. Threaded messages are never deleted if a channel overrides the global policy

Server Setup Information:

  • Version of Rocket.Chat Server: 3.14.4
  • Deployment Method: snap

Additional context

I created a debug build to investigate this issue. I logged room.retention at the following location and found that ignoreThreads was undefined in all cases where a channel had a retention policy enabled:

const { maxAge = 30, filesOnly, excludePinned, ignoreThreads } = room.retention;

The above then calls cleanRoomHistory() and passes the ignoreThreads variable to it. The body of the following if statement is never executed for rooms that override the global policy, due to ignoreThreads always being undefined:

if (!ignoreThreads) {
const threads = new Set();
Messages.findThreadsByRoomIdPinnedTimestampAndUsers({ rid, pinned: excludePinned, ignoreDiscussion, ts, users: fromUsers }, { fields: { _id: 1 } })
.forEach(({ _id }) => threads.add(_id));
if (threads.size > 0) {
Subscriptions.removeUnreadThreadsByRoomId(rid, [...threads]);
}
}

The ignoreThreads variable also gets passed to Messages.removeByIdPinnedTimestampLimitAndUsers() here:

const count = Messages.removeByIdPinnedTimestampLimitAndUsers(rid, excludePinned, ignoreDiscussion, ts, limit, fromUsers, ignoreThreads);

Again, the body of the following if statement is never executed because ignoreThreads is always undefined:

if (ignoreThreads) {
query.tmid = { $exists: 0 };
query.tcount = { $exists: 0 };
}

Temporary Workaround

This bug can be resolved by logging on to the server, connecting to the MongoDB instance, and running the following commands:

use parties
db.rocketchat_room.update({"retention.enabled": true}, {"$set": {"retention.ignoreThreads":false}}, {"multi":true})

This sets the retention.ignoreThreads setting to false on all rooms/channels that have a retention policy enabled, which will result in threaded messages being deleted by the message pruning task (provided they are older than the maximum age).

@johncrisp
Copy link

Hi and thanks for reporting this.

As per the guide in the bug reporting template please try and test this on the lastest code if at all possible just to make sure it hasn't been fixed already.

https://rocket.chat/docs/contributing/reporting-issues

@NickstaDB
Copy link
Author

Hell naw, over to you lot.

@Govi59
Copy link

Govi59 commented Oct 26, 2021

Similar to #18738 and #19731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants