❔ Best way to display a continually updating list of messages
This is a component in a Blazor WASM chat app I'm developing which job is to display a list of messages. However I'm wondering whether this is an alright-ish way to go about keeping a continually updating list of messages, because to me it feels a bit iffy. Especially the fact I have this
Remove
call which has to iterate through all the messages to remove it. I don't know how well this would scale or whether there is a better approach.17 Replies
I have never touched blazor WASM, but Ideally you'd want to track the messages by their IDs
That makes sense
I have something for a console history. Because of that I don't have the removal part.
With 5k lines it still works without freezing. I haven't tested more.
You could use a HashSet but iterating would be slower then.
So I guess your impl is good
Thing is that this needs to be ordered
And hash sets have no order
Oh yea makes sense obviously
I guess you could try to return thousands of msgs and remove random ones to see how it behaves
you can keep your list sorted by message id that way you dont have to traverse the full list
That'd be better I suppose
I could do a binary search thing, either by ID or by message creation date
yeah you could also go for a twitter/discord snowflake approach for the timestamp and id
hmm, I haven't investigated how that works. Got any resources for it?
@🌈 Thinker 🌈
Just a note whether you need need a snowflake or not depends on many factors, because it's usually used for distributed systems, but the general idea might help you nonetheless
https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake
This was the official announcement from Twitter
https://github.com/aevitas/flakeid/blob/master/src/FlakeId/Id.cs
And here is an C# implementation of snowflake I found on github
This is also how discord encodes it
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
My messages already have a timestamp so I don't think it's necessary to encode that in the ID
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I only have a single server so that's probably not an issue
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.