Tuesday, February 27, 2018

Channels 1.x

Hello,

I'm using django-channels for some months and I'm observing a behaviour for which I don't know if it's a normal one, or a misconfiguration from my side.
Here is my pretty simple consumer :

# Connected to websocket.connect
@channel_session_user_from_http
def ws_task_connect(message):
   
if isinstance(message.user, AnonymousUser):
        message
.reply_channel.send({"close": True})
   
else:
       
# Accept connection
        message
.reply_channel.send({"accept": True})
       
# Add them to the right group
       
Group("task-%d" % message.user.pk).add(message.reply_channel)
        refresh_current_tasks
(message.user, send_if_empty=False)

# Connected to websocket.disconnect
@enforce_ordering
@channel_session_user
def ws_task_disconnect(message):
   
Group("task-%d" % message.user.pk).discard(message.reply_channel)

It does work but if my user does refresh the page, I see a new entry in the session table (django_session). In other terms, if my user browse 20 different pages in his administration panel, I'll have 21 entries in the django_session table (1 session created by the native Django SessionMiddleware, 20 for every WebSocket created by browsing the 20 pages). Is it normal or shouldn't this by reduced to 2 entries?

For information, upgrading to django-channels 2 is not yet an option for this project.

Kind regards,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/160e0c3b-c74e-4683-acf6-a882716b9c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment