Avoid saving user_presence twice when creating a new object.

(imported from commit 72af41b4e0b85f9a8605f5040c321c80e16e8a97)
This commit is contained in:
Tim Abbott
2013-06-24 13:05:41 -04:00
parent 8f0fbfb562
commit c87d182102

View File

@@ -795,7 +795,8 @@ def do_update_user_presence(user_profile, client, log_time, status):
(presence, created) = UserPresence.objects.get_or_create(
user_profile = user_profile,
client = client,
defaults = {'timestamp': log_time})
defaults = {'timestamp': log_time,
'status': status})
except IntegrityError:
transaction.commit()
presence = UserPresence.objects.get(user_profile = user_profile,
@@ -806,9 +807,10 @@ def do_update_user_presence(user_profile, client, log_time, status):
was_idle = presence.status == UserPresence.IDLE
became_online = (status == UserPresence.ACTIVE) and (stale_status or was_idle)
presence.timestamp = log_time
presence.status = status
presence.save(update_fields=["timestamp", "status"])
if not created:
presence.timestamp = log_time
presence.status = status
presence.save(update_fields=["timestamp", "status"])
if not user_profile.realm.domain == "mit.edu" and (created or became_online):
# Push event to all users in the realm so they see the new user