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

Feat/purge messages upto 24 hrs in current channel #982

Draft
wants to merge 35 commits into
base: develop
Choose a base branch
from

Conversation

ankitsmt211
Copy link
Member

@ankitsmt211 ankitsmt211 commented Dec 10, 2023

For earlier context related to PR, #945

resolves #912

Workflow

  1. Message Sent: A user sends a message in a Discord channel.
  2. Log Message Metadata: The Message Listener detects the new message and logs its metadata into the Database Table.
  3. Periodic Cleanup: The Cleanup Routine periodically checks the database for messages older than 24 hours and deletes them.
  4. Database Overload Prevention: The Emergency Brake activates if the database approaches its record limit, preventing spamming and overload.
  5. Database Size Management: The Record Management Subroutine deletes the oldest records to make space for new entries when nearing the database limit for this feature(~7.5k records).

Includes

  • Database Table: Tracks message metadata.
  • Cleanup Routine: Removes records older than 24 hours.
  • Message Listener: Logs new messages into the database.
  • New Package: Dedicated to the feature.
  • New Command: /purge-in-channel.
  • Issue Resolution: Resolves Delete last X messages from user for moderation #912.

Additions

  • Emergency Brake: Prevents spamming DB after cetain limit.
  • Record Management Subroutine: Deletes oldest records to free up DB limit for this feature once triggered.

Command Interface

image

when there's no records:
image

if there's any records within selected duration:
image

Note: Duration is optional, if skipped it defaults to last hour.

@ankitsmt211 ankitsmt211 added the enhancement New feature or request label Dec 10, 2023
@ankitsmt211 ankitsmt211 added new command Add a new command or group of commands to the bot priority: low labels Dec 10, 2023
@ankitsmt211 ankitsmt211 self-assigned this Dec 10, 2023
@ankitsmt211 ankitsmt211 requested review from a team as code owners December 10, 2023 18:21
@ankitsmt211 ankitsmt211 changed the title Feat/delete last hour messages Feat/purge messages upto 24 hrs Dec 16, 2023
@ankitsmt211 ankitsmt211 changed the title Feat/purge messages upto 24 hrs Feat/purge messages upto 24 hrs in current channel Dec 16, 2023
private static final int MESSAGES_RECORDS_MAX_LIMIT = 7500;
private static final int MESSAGES_RECORDS_THRESHOLD = MESSAGES_RECORDS_MAX_LIMIT - 100;
private static final int RECORDS_TO_TRIM = 500;
static AtomicInteger recordsCounter = new AtomicInteger(0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the PR is getting too old now and so much stuff to review , flagging the important bit, is using atomic justified here?
the goal is to limit only certain no of db entries(recordsCounter), which is modified across package in PurgeMessageListener (incrementCounterByOne) on each new message and in both PurgeHistoryCommand and PurgeExpiredMessageHistory (decrementCountByOne) on each deletion of record/message.

@ankitsmt211
Copy link
Member Author

converting this PR to draft, feel like it needs a bit of refactoring considering moderation usecase per channel basis might not be suited anymore.

@ankitsmt211 ankitsmt211 marked this pull request as draft May 13, 2024 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new command Add a new command or group of commands to the bot priority: low
Projects
Status: No Status
Development

Successfully merging this pull request may close these issues.

Delete last X messages from user for moderation
4 participants