summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/bitmask_libraries/session.py12
-rw-r--r--service/pixelated/resources/mails_resource.py2
-rw-r--r--service/pixelated/support/__init__.py30
3 files changed, 37 insertions, 7 deletions
diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py
index 9e908ce5..f28d9f59 100644
--- a/service/pixelated/bitmask_libraries/session.py
+++ b/service/pixelated/bitmask_libraries/session.py
@@ -53,12 +53,20 @@ class LeapSession(object):
self.fresh_account = False
self.incoming_mail_fetcher = None
self.account = None
+ self._has_been_synced = False
+ self._sem_intial_sync = defer.DeferredLock()
register(events.KEYMANAGER_FINISHED_KEY_GENERATION, self._set_fresh_account, uid=self.account_email())
@defer.inlineCallbacks
def initial_sync(self):
- yield self.sync()
- yield self.after_first_sync()
+ yield self._sem_intial_sync.acquire()
+ try:
+ if not self._has_been_synced:
+ yield self.sync()
+ yield self.after_first_sync()
+ self._has_been_synced = True
+ finally:
+ yield self._sem_intial_sync.release()
defer.returnValue(self)
@defer.inlineCallbacks
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index 1c322d35..c87d4ca2 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -183,7 +183,7 @@ class MailsResource(BaseResource):
if isinstance(error.value, SMTPDownException):
respond_json_deferred({'message': str(error.value)}, request, status_code=503)
else:
- err(error, 'something failed')
+ err(error, 'error occurred while sending')
respond_json_deferred({'message': 'an error occurred while sending'}, request, status_code=422)
deferred = self._handle_post(request)
diff --git a/service/pixelated/support/__init__.py b/service/pixelated/support/__init__.py
index 80ecaa2e..9ac52fe0 100644
--- a/service/pixelated/support/__init__.py
+++ b/service/pixelated/support/__init__.py
@@ -22,13 +22,34 @@ from twisted.internet import defer
log = logging.getLogger(__name__)
+def _start_stopwatch():
+ return (time.time(), time.clock())
+
+
+def _stop_stopwatch(start):
+ start_time, start_clock = start
+ end_clock = time.clock()
+ end_time = time.time()
+ clock_duration = end_clock - start_clock
+ time_duration = end_time - start_time
+ if time_duration < 0.00000001: # avoid division by zero
+ time_duration = 0.00000001
+
+ estimate_percent_io = ((time_duration - clock_duration) / time_duration) * 100.0
+
+ return time_duration, clock_duration, estimate_percent_io
+
+
def log_time(f):
@wraps(f)
def wrapper(*args, **kwds):
- start = time.clock()
+ start = _start_stopwatch()
+
result = f(*args, **kwds)
- log.info('Needed %f ms to execute %s' % ((time.clock() - start), f))
+
+ time_duration, clock_duration, estimate_percent_io = _stop_stopwatch(start)
+ log.info('Needed %fs (%fs cpu time, %.2f%% spent outside process) to execute %s' % (time_duration, clock_duration, estimate_percent_io, f))
return result
@@ -38,12 +59,13 @@ def log_time(f):
def log_time_deferred(f):
def log_time(result, start):
- log.info('after callback: Needed %f ms to execute %s' % ((time.clock() - start), f))
+ time_duration, clock_duration, estimate_percent_io = _stop_stopwatch(start)
+ log.info('after callback: Needed %fs (%fs cpu time, %.2f%% spent outside process) to execute %s' % (time_duration, clock_duration, estimate_percent_io, f))
return result
@wraps(f)
def wrapper(*args, **kwds):
- start = time.clock()
+ start = _start_stopwatch()
result = f(*args, **kwds)
if isinstance(result, defer.Deferred):
result.addCallback(log_time, start=start)