Drop session field from Connection model, move transaction wrapper from on_message to dispatch handler.

This commit is contained in:
Tyson Clugg 2015-04-29 19:40:30 +10:00
parent 93be313adb
commit 1a91693d1f
3 changed files with 25 additions and 14 deletions

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('dddp', '0005_auto_20150427_1209'),
]
operations = [
migrations.AlterUniqueTogether(
name='connection',
unique_together=set([]),
),
migrations.RemoveField(
model_name='connection',
name='session',
),
]

View file

@ -105,24 +105,14 @@ class Connection(models.Model, object):
"""Django DDP connection instance."""
session = models.ForeignKey('sessions.Session')
connection_id = AleaIdField()
server_addr = models.CharField(max_length=255)
remote_addr = models.CharField(max_length=255)
version = models.CharField(max_length=255)
class Meta(object):
"""Connection model meta."""
unique_together = [
['connection_id', 'session'],
]
def __str__(self):
"""Text representation of subscription."""
return u'%s/\u200b%s/\u200b%s' % (
self.session_id,
return u'%s/\u200b%s' % (
self.connection_id,
self.remote_addr,
)
@ -131,7 +121,7 @@ class Connection(models.Model, object):
@python_2_unicode_compatible
class Subscription(models.Model, object):
"""Session subscription to a publication with params."""
"""Subscription to a publication with params."""
_publication_cache = {}
connection = models.ForeignKey(Connection)

View file

@ -145,7 +145,6 @@ class DDPWebSocketApplication(geventwebsocket.WebSocketApplication):
self.connection = None
self.logger.info('- %s %s', self, reason or 'CLOSE')
@transaction.atomic
def on_message(self, message):
"""Process a message received from remote."""
if self.ws.closed:
@ -192,6 +191,7 @@ class DDPWebSocketApplication(geventwebsocket.WebSocketApplication):
except MeteorError, err:
self.error(err)
@transaction.atomic
def dispatch(self, msg, kwargs):
"""Dispatch msg to appropriate recv_foo handler."""
# enforce calling 'connect' first
@ -280,7 +280,6 @@ class DDPWebSocketApplication(geventwebsocket.WebSocketApplication):
this.version = version
this.support = support
self.connection = Connection.objects.create(
session_id=this.request.session.session_key,
server_addr='%d:%s' % (
backend_pid,
self.ws.handler.socket.getsockname(),