From 669a3070bd28e9cce2cc8ccd13f0a97343565549 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 18 Jan 2017 11:23:23 -0500 Subject: [PATCH] Only parse request URL in track_and_log when necessary --- endpoints/trackhelper.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/endpoints/trackhelper.py b/endpoints/trackhelper.py index 5c336643c..0aa66cefa 100644 --- a/endpoints/trackhelper.py +++ b/endpoints/trackhelper.py @@ -56,13 +56,6 @@ def track_and_log(event_name, repo_obj, analytics_name=None, analytics_sample=1, metadata['public'] = True analytics_id = 'anonymous' - request_parsed = urlparse(request.url_root) - extra_params = { - 'repository': '%s/%s' % (namespace_name, repo_name), - 'user-agent': request.user_agent.string, - 'hostname': request_parsed.hostname, - } - # Publish the user event (if applicable) logger.debug('Checking publishing %s to the user events system', event_name) if authenticated_user and not authenticated_user.robot: @@ -80,7 +73,16 @@ def track_and_log(event_name, repo_obj, analytics_name=None, analytics_sample=1, if random.random() < analytics_sample: if analytics_name is None: analytics_name = event_name + logger.debug('Logging the %s to Mixpanel', analytics_name) + + request_parsed = urlparse(request.url_root) + extra_params = { + 'repository': '%s/%s' % (namespace_name, repo_name), + 'user-agent': request.user_agent.string, + 'hostname': request_parsed.hostname, + } + analytics.track(analytics_id, analytics_name, extra_params) # Log the action to the database.