Skip to content

refactor: resolve TODOs, optimise queries, and improve shutdown safety#1061

Merged
confuser merged 2 commits intomasterfrom
refactor/query-efficiency-and-todo-sweep
Apr 4, 2026
Merged

refactor: resolve TODOs, optimise queries, and improve shutdown safety#1061
confuser merged 2 commits intomasterfrom
refactor/query-efficiency-and-todo-sweep

Conversation

@confuser
Copy link
Copy Markdown
Member

@confuser confuser commented Apr 4, 2026

Summary

  • Transaction safety: Wraps RollbackCommand operations in TransactionHelper.runInTransaction() for atomicity, including RollbackData creation inside the transaction
  • Query efficiency: Eliminates N+1 patterns across storage classes (PlayerWarnStorage, PlayerHistoryStorage, PlayerReportStorage), replaces in-memory aggregation with SQL GROUP BY/UNION ALL, batches bulk operations with chunked IN clauses, and removes double isBanned/getBan lookups across all listeners and commands
  • Shutdown safety: Runs PlayerStorage autocomplete setup on an async thread with a volatile shutdown guard, adds cancelAll() to CommonScheduler with implementations for Sponge API 7 and Velocity (tracking only repeating tasks to prevent unbounded memory growth)
  • Code quality: Resolves TODO comments, extracts generic cache helpers in RollbackSync using Predicate/Consumer, introduces typed HistoryEntry replacing raw HashMap for history methods, deduplicates HistoryStorage query logic, caches permission checks before async blocks, and fixes ActivityStorage connection management with try-with-resources

Key changes

Area Files What changed
Transactions RollbackCommand Full rollback wrapped in single transaction
SQL optimisation PlayerWarnStorage, PlayerHistoryStorage, PlayerReportStorage, InfoCommand, FindAltsCommand, KickAllCommand Batch deletes, UNION ALL counts, chunked updates, batched inserts
Double lookups CommonJoinListener, CommonChatListener, CommonCommandListener, InfoCommand Single getBan()/getMute() call + null check
Shutdown PlayerStorage, BanManagerPlugin, CommonScheduler, SpongeScheduler, VelocityScheduler, BMSpongePlugin, BMVelocityPlugin Graceful async autocomplete teardown, scheduler cancelAll()
Refactoring RollbackSync, HistoryStorage, ActivityStorage, HistoryEntry (new) Generic helpers, typed return values, try-with-resources
Threading UnbanCommand, UnmuteCommand Permission checks cached before runAsync

Breaking changes

  • HistoryStorage methods now return List<HistoryEntry> instead of ArrayList<HashMap<String, Object>> (internal API, affects InfoCommand consumers only)

Test plan

  • ./gradlew compileJava — all modules compile successfully
  • ./gradlew :BanManagerCommon:test — all 291 tests pass (14 skipped)
  • Manual testing: verify /bmrollback with reports type fires PlayerReportDeletedEvent correctly
  • Manual testing: verify Sponge API 7 and Velocity plugin shutdown cancels repeating tasks cleanly
  • Manual testing: verify /bminfo statistics display correctly with UNION ALL query

confuser added 2 commits April 4, 2026 13:47
- Wrap RollbackCommand in transaction for atomicity; restore
  PlayerReportDeletedEvent firing for reports case
- Extract generic cache helpers in RollbackSync using Predicate/Consumer
- Add bulk markAllRead() to PlayerWarnStorage, replace N+1 deleteRecent
  with single DELETE subquery
- Replace SELECT-then-loop-delete in PlayerHistoryStorage.purge() with
  DELETE WHERE IN; batch save() updates with chunked IN clause
- Replace in-memory aggregation in getNamesSummary() with SQL GROUP BY
- Batch report deletions in PlayerReportStorage while preserving events
- Hoist repeated queryForId out of punishAlts loop in CommonJoinListener
- Eliminate double isBanned/getBan lookups across listeners and commands
- Combine InfoCommand 8 aggregate queries into single UNION ALL subquery
- Batch FindAltsCommand per-alt ban record lookups
- Batch KickAllCommand kick logging with callBatchTasks
- Run PlayerStorage autocomplete async with volatile shutdown guard
- Cache permission checks before async blocks in Unban/UnmuteCommand
- Add cancelAll() to CommonScheduler; implement in Sponge API 7 and
  Velocity schedulers tracking only repeating tasks
- Introduce typed HistoryEntry replacing HashMap for history methods
- Fix ActivityStorage connection management with try-with-resources
- Deduplicate HistoryStorage query methods
…markAllRead

- RollbackCommandTest: verify reports rollback fires PlayerReportDeletedEvent
  per report and deletes all matching reports from DB
- InfoCommandTest: exercise UNION ALL statistics query with records across
  all count categories (ban records, mute records, warns, notes, reports)
- PlayerWarnStorageTest: verify markAllRead bulk update marks only the
  target player's unread warnings without affecting other players
@confuser confuser merged commit 4145882 into master Apr 4, 2026
18 checks passed
@confuser confuser deleted the refactor/query-efficiency-and-todo-sweep branch April 4, 2026 13:08
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