Kraigie / nostrum

Elixir Discord Library
https://kraigie.github.io/nostrum/
MIT License
589 stars 125 forks source link

Message cache #595

Closed Th3-M4jor closed 1 month ago

Th3-M4jor commented 1 month ago

This is still a work in progress, but is the beginnings of a message cache for Nostrum.

Still needs to be hooked into the event handler and I need to test it.

Adds a new Mnesia backed message cache, but defaults to a no-op cache for most users simply because it would use a lot more memory and most users don't need a message cache.

Also improves the way pluggable caching configuration works, such that users can provide a configuration to each cache, such as configuring a maximum size or how many messages get evicted when the cache reaches its maximum size

jchristgit commented 1 month ago

Thanks, this looks solid already! There is one problem with QLC that I wonder if we can contribute a smart fix for upstream: qlc:keysort will always sort the entire table (as a list) in memory, so it's not exactly efficient on big tables. For large message caches this would mean a temporary bloating of memory on every cull. For the other "sorted by age" queries I think it's fine. Should we maybe change the cull of old messages somehow differently... I'm thinking.. maybe we can memorize the oldest message somehow, but then we have to somehow update it - how would that work - or we need to, hm, I wonder

Th3-M4jor commented 1 month ago

Still need to do some real testing of it myself but other than that, this should be ready.

Do note that there are breaking changes that come with this

jchristgit commented 1 month ago

Thanks!