ygimenez / Pagination-Utils

A collection of methods to make message pagination with JDA easier.
GNU Lesser General Public License v2.1
27 stars 7 forks source link

Clean events map #25

Closed avurro closed 3 years ago

avurro commented 3 years ago

Every day the bot adds thousands of events that accumulate in the map shown below. It would be better to find a way to cleanse it of older events.

This map in MessageListener class: private final Map<String, Consumer<GenericMessageReactionEvent>> events = new HashMap<>(); It grows continuously if I use methods without timeout. On the other hand, if I set the timeout, the WebSocketClient disconnects every 15/20 minutes.

ygimenez commented 3 years ago

You can get the events map with Pages.getHandler() then use removeEvent(Message) to remove an event from it, or delete the messages which also trigger event removal. Nonetheless I'll add a clear() method to it for cleanup on the next update.

About the timeout, I'm not sure it's the reason for WebSocketClient disconnects since it uses Executors as scheduler, maybe it's something else?

avurro commented 3 years ago

About the timeout, I'm not sure it's the reason for WebSocketClient disconnects since it uses Executors as scheduler, maybe it's something else?

The only operation I did was to switch from paginate with timeout to paginate without and I solved it.

You can get the events map with Pages.getHandler() then use removeEvent(Message) to remove an event from it, or delete the messages which also trigger event removal. Nonetheless I'll add a clear() method to it for cleanup on the next update.

ok, thanks! But there is a method that return all events registered ?

ygimenez commented 3 years ago

ok, thanks! But there is a method that return all events registered ?

No since direct manipulation of the map would be very bad for the library itself.

ygimenez commented 3 years ago

Added clear() and getEventMap() for MessageHandler in release 2.2.0. Do note, however, that the returned map is unmodifiable.