From b700202e4f42b545c25f7d11fda579bd3cd0d01b Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 26 May 2014 17:28:59 -0700 Subject: [PATCH] Quiet some of the logspam around instances --- api.py | 2 +- channel.py | 13 +++++++++---- lib/models.py | 14 ++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/api.py b/api.py index 26a4649..4724087 100644 --- a/api.py +++ b/api.py @@ -134,7 +134,7 @@ def Unpin(google_user, client, instance_id, args): try: models.Subject.FindOrCreate(subject).Unpin( - client.parent_key(), sender_message_id, instance) + client.parent_key(), sender_message_id, instance.key()) except models.AccessDenied: logging.exception('Pin access denied') return { diff --git a/channel.py b/channel.py index 9644414..be95c44 100644 --- a/channel.py +++ b/channel.py @@ -28,6 +28,9 @@ class OnChannelConnect(webapp2.RequestHandler): def post(self): instance_id = self.request.get('from') instance = models.Instance.FromID(instance_id) + if not instance: + logging.error('Channel opened with invalid instance_id: %s', instance_id) + return instance.active = True instance.put() @@ -36,17 +39,19 @@ class OnChannelDisconnect(webapp2.RequestHandler): @utils.local_namespace def post(self): instance_id = self.request.get('from') - instance = models.Instance.FromID(instance_id) + instance_key = db.Key.from_path('Instance', instance_id) - subscriptions = models.Subscription.all().filter('instance =', instance) + subscriptions = models.Subscription.all().filter('instance =', instance_key) for subscription in subscriptions: subscription.delete() - pins = models.Pin.all().filter('instance =', instance) + pins = models.Pin.all().filter('instance =', instance_key) for pin in pins: pin.Delete() - instance.delete() + instance = models.Instance.FromID(instance_id) + if instance: + instance.delete() app = webapp2.WSGIApplication([ diff --git a/lib/models.py b/lib/models.py index 83b72b8..c026efd 100644 --- a/lib/models.py +++ b/lib/models.py @@ -253,17 +253,17 @@ class Subject(db.Model): subscription.SendMessage(event) @db.transactional(xg=True) - def RemovePin(self, sender, sender_message_id, instance): + def RemovePin(self, sender, sender_message_id, instance_key): # Reload the subject and instance to establish a barrier subject = Subject.get(self.key()) - instance = Instance.get(instance.key()) + Instance.get(instance_key) pins = ( Pin.all() .ancestor(subject) .filter('sender =', sender) .filter('sender_message_id =', sender_message_id) - .filter('instance =', instance)) + .filter('instance =', instance_key)) events = [] for pin in pins: @@ -272,9 +272,9 @@ class Subject(db.Model): return (events, list(Subscription.all().ancestor(subject))) - def Unpin(self, sender, sender_message_id, instance): + def Unpin(self, sender, sender_message_id, instance_key): self.VerifyWritable(sender) - events, subscriptions = self.RemovePin(sender, sender_message_id, instance) + events, subscriptions = self.RemovePin(sender, sender_message_id, instance_key) for event in events: for subscription in subscriptions: subscription.SendMessage(event) @@ -378,4 +378,6 @@ class Pin(db.Model): } def Delete(self): - self.parent().Unpin(self.sender, self.sender_message_id, self.instance) + self.parent().Unpin( + self.sender, self.sender_message_id, + Pin.instance.get_value_for_datastore(self))