r3labs / sse

Server Sent Events server and client for Golang
Mozilla Public License 2.0
870 stars 180 forks source link

Feature: delete old messages in the eventlog after a custom interval #100

Open frederikhors opened 3 years ago

frederikhors commented 3 years ago

I'm using your amazing project for the first time (and I'm new to Go too).

I have a doubt.

If I don't use

sseServer.AutoReplay = false

each client (also the new ones) connects to a stream and gets all the messages from the past too.

My question is: is there a limit?

Example: a client connected at 09:00 and receives 100 messages. Another connects at 10:00 and receives the 100 messages too, plus the new ones that will arrive?

Do these messages remain in memory on the server?

If so, is there a way for this not to happen and to have a maximum time after which messages are deleted from memory?

Thanks for your commitment!

purehyperbole commented 3 years ago

Hey @frederikhors, welcome to the Go community!

Good question! Currently enabling stream replay will keep all messages for the life of the stream.

The current implementation does not support a way to limit this and would probably need to be re-implemented to handle deletion of older elements.

I currently don't have the time to implement this, but if you feel you are able to add this please feel free to give it a go!

frederikhors commented 3 years ago

Currently enabling stream replay will keep all messages for the life of the stream.

Ok. This is what I meant. I don't need it for now because if any client misses some message it doesn't matter.

I verified in debugging and in fact the EventLog is never filled with AutoReplay = false. Good.

As soon as I have some time I'll try to figure out how to slowly delete the messages with AutoReplay = true. Maybe using the timestamp and TTL as you already do for sending.

If you have time you can obviously do it, I'm not taking the exclusivity! 😄

codewinch commented 3 years ago

@frederikhors you might want to use a different method for persisting messages so that you can control that on your own.