Skip to content

feat(purge): delete messages older than 14 days too - #394

Open
Ferdinand99 wants to merge 4 commits into
v5.3from
feat/53-purge-old-messages
Open

Ferdinand99 wants to merge 4 commits into
v5.3from
feat/53-purge-old-messages

Conversation

@Ferdinand99

Copy link
Copy Markdown
Owner

What

/purge used channel.bulkDelete(messages, true), which silently skipped messages older than 14 days. It now deletes messages of any age.

  • Discord: messages younger than 14 days (cut computed from the snowflake timestamp, with a few minutes of margin) are bulk-deleted as before (2-100). Older ones are deleted one at a time, paced at about one per 1.1 s. A 429 is waited out (retry_after) and the same message is retried, up to 5 times; a message that keeps failing is counted as failed. A bulk error "too old" (50034) or a message the bulk call skipped falls back to single deletes.
  • Fluxer: fluxer_api POST /channels/:id/messages/bulk-delete (MessageDeleteService.bulkDeleteMessages) has no age limit, takes 1-100 ids, and only needs Manage Messages. So on Fluxer every message goes through the bulk route (filterOld = false). The route is limited to 10 requests per 10 s per channel, the single delete to 20 per 10 s, so the single-delete fallback there is paced at 550 ms.
  • Cap stays at 100 messages per command.
  • Progress: when a Discord purge has old messages, the reply is updated ("Deleted 40 of 100...", at most every 2.5 s) and has a Stop button. Only the person who ran the command and server admins (Administrator, which includes the owner) can use it; anyone else gets an ephemeral refusal.
  • One at a time: a second /purge in the same channel is refused with a clear message until the first finishes or is stopped (lock keyed by guildKey() + channel id, released in finally).
  • The final reply says how many were deleted and how many failed (already gone / missing permission / other); a stopped purge says how many were left untouched.
  • Options, permission checks and the mod-log entry are unchanged (the entry also lists failed and stopped-early counts when relevant).
  • Command description and docs/modules/moderation.md no longer say "younger than 14 days".

Tests

New test/purgeCommand.test.js (32 tests): split by age, single-delete pacing with fake 429s (both SDKs' error shapes), failure classification, stop button permissions, one-at-a-time lock, Fluxer path and the compat adapter, the 100 cap, and the command flow.

Lint, prettier, and the full SQLite and Postgres 16 suites pass.

/purge now deletes messages of any age. On Discord, messages younger than
14 days are bulk-deleted and older ones are deleted one at a time at the
platform's pace, waiting out 429s. Fluxer's bulk route has no age limit, so
everything goes through it there. A long purge shows progress with a Stop
button (the person who ran it and server admins), one purge runs per
channel at a time, and the final reply reports deleted and failed counts.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify code review View in Graphify

Review completed · 7668584b97b2

Tip

Merge confidence: 5/5 · Looks safe to merge · ⚪ Medium impact
No issues reported

The purge command now handles older messages with paced single deletes, while retaining bulk deletion for eligible messages.

Full summary

The purge command now handles older messages with paced single deletes, while retaining bulk deletion for eligible messages. It also adds progress updates, a Stop button for longer Discord purges, and a per-channel lock.

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • 3 of 3 changed files inspected. This is scope, not a correctness guarantee.
Code graph and static checks · 45 functions depend on this change

Impact & health

Impact — 45 functions depend on the 45 functions this change touches.

Health — this change adds coupling hotspots:

  • new: purgeMessages() — 3 callers, 6 callees

Formal checks — 45 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Health delta baseline: last indexed commit a9ec8af (diverged from this PR's base — delta is approximate).

Gate & verification

✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 45 function(s) in the blast radius were not formally verified this run

Test selection

674 of 674 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety (noncode-change, uncovered-code) — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Access/DashboardAccessTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Access/Round3Tests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Account/AccountConnectTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Account/AccountModelTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Account/ConnectCallbackSourceTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Account/NoDashboardLinkSourceTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Appeals/AppealsReviewTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Applications/ApplicationFormsTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Applications/ApplicationPassthroughTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Applications/ApplicationSubmissionsTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Applications/ApplicationWireTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Audit/AuditHistoryTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Audit/AuditLogTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Auth/CallbackIssuerAddressTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Auth/CallbackIssuerTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Auth/KeychainTokenStoreTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Auth/PKCETests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Auth/SignInRequestTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Auth/TokenStoreTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Changelog/ChangelogTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Commands/CommandOverridesTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Economy/CollectiblePictureTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Economy/EconomyAdminTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Economy/EconomyMembersTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Economy/InventoryTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Economy/ShopExtrasTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Economy/ShopItemsTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Economy/ShopModelTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Embeds/EmbedDraftTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Embeds/ModuleLimitsTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Events/CommunityReviewFixesTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Events/EventEndpointsTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Giveaways/GiveawayActionsTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/GuildSettings/CommandPrefixTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/GuildSettings/GuildSettingsTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Health/HealthTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Import/P6Tests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Insights/InsightsTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Leaderboard/LeaderboardTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Members/MemberDataTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Members/MemberSearchTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Messages/ComposedMessagesModelTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Messages/ComposedMessagesTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Models/ModelDecodingTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Models/ServerListTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Models/Sylo52PolishTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Models/UnknownKeysTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Models/Utf16TextLimitTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/Moderation/ModerationTests.swift — full-run-safety
  • apps/sylo-ios/SyloKit/Tests/SyloKitTests/ModuleSettings/AfkSettingsTests.swift — full-run-safety
  • … and 624 more

⚠️ non-code file(s) changed (docs/modules/moderation.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)

⚠️ changed code file(s) with no mapped test (docs/modules/moderation.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Every flagged function

  • purgeMessages() in src/bot/lib/purgeMessages.js:148 · 3 callers, 6 callees: fans out to 6 callees (efferent coupling)

…keep old pinned messages

- end the run as timed out instead of waiting past the 15-minute interaction token
- post the mod-log entry before the final reply and tolerate a failing reply
- the progress reply is ephemeral, so only the person who ran the command can stop it;
  drop the server-admin wording
- keep pinned messages older than 14 days, as before, and say how many were kept
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 this pull request may close these issues.

1 participant