Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Counting reply_channels in a Group #388
Hi folks, this is a pseudo-enhancement request discussion. If there's a better forum for this, please advise.
I've been tinkering with the chat use case. One of the first things I've tried to do is determine how many users ("reply_channels") are in a "room" (Group) at a time. In my head, calling
Currently, retrieving this count requires getting the RedisChannelLayer instance and asking for all of the key/value pairs from the Group zset, then getting the length of the returned list:
This also works:
It feels dirty to retrieve all the data when you just need the count. When using redis as a backend, we can issue the zcard command to retrieve row count for a given zset, i.e:
My knowledge/research falls short at this point. Could we extend Group class this enhancement be generic enough to implement for all backends? The hacky way can be implemented easily:
Update - we can use the native connection in a backend-specific (
This has been possible from day one, but I want to ask a different question: why do you think this would be useful?
Basically, every point at which the API gets extended is one more point where backends are not free to optimise how they wish, and providing accurate lengths is one of these things. I added
It's deliberately not exposed via the Channels API though as it doesn't perform well and I don't want to invest time and insertion speed into making it do so without a compelling argument for having lengths. In particular, you cannot use group lengths for presence, as channels may exist in a group for up to 24 hours (by default) before the last cleanup gets them if they disconnect uncleanly.
If you have a good set of scenarios that channels can fulfill by adding group size that it can do accurately and in a way that won't mislead people, please share! That's why this hasn't been in here until now. If not, then I'm going to have to say no.