Only parse request URL in track_and_log when necessary

This commit is contained in:
Joseph Schorr 2017-01-18 11:23:23 -05:00
parent 89229a8f2c
commit 669a3070bd

View file

@ -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.