Rfaulk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/79038


Change subject: mod. handle url parsing to generate unique hashes.
......................................................................

mod. handle url parsing to generate unique hashes.

Change-Id: I5b9d33a425854ceac6a85c98f1dbd231fbfbb223
---
M user_metrics/api/views.py
1 file changed, 11 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/user-metrics 
refs/changes/38/79038/1

diff --git a/user_metrics/api/views.py b/user_metrics/api/views.py
index f7b6c6c..9cf29a8 100644
--- a/user_metrics/api/views.py
+++ b/user_metrics/api/views.py
@@ -32,6 +32,7 @@
 from hashlib import sha1
 
 # upload files
+import re
 import csv
 import json
 
@@ -389,19 +390,23 @@
     TODO - change app.route to accept regex to avoid passing unused vars
     """
 
-    # Generate url hash
-    url_hash = sha1(request.url.encode('utf-8')).hexdigest()
-
     # Check for refresh flag
     refresh = True if 'refresh' in request.args else False
-    data = get_data(request)
+
+    # Generate url hash - replace 'refresh' in url
+    url = re.sub(REFRESH_REGEX, '', request.script_root + request.path)
+    url = re.sub('/cohorts/', '', url)
+    url_hash = sha1(url.encode('utf-8')).hexdigest()
+
+    # Determine whether result is already cached
+    data = get_data(url)
 
     # Is the request already running or queued?
     is_queued = umapi_broker_context.is_item(REQUEST_BROKER_TARGET, url_hash)
     is_running = umapi_broker_context.is_item(PROCESS_BROKER_TARGET, url_hash)
 
     logging.info(__name__ + ' :: REQ {0}:{1}\n\tqueued={2}\n\tprocessing={3}'.
-        format(url_hash, request.url, str(is_queued), str(is_running)))
+        format(url_hash, url, str(is_queued), str(is_running)))
 
     # Determine if response is already cached
     if data and not refresh:
@@ -417,8 +422,7 @@
 
     # Add the request to the queue
     else:
-        umapi_broker_context.add(REQUEST_BROKER_TARGET, url_hash, request.url)
-
+        umapi_broker_context.add(REQUEST_BROKER_TARGET, url_hash, url)
         return render_template('processing.html')
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/79038
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5b9d33a425854ceac6a85c98f1dbd231fbfbb223
Gerrit-PatchSet: 1
Gerrit-Project: analytics/user-metrics
Gerrit-Branch: master
Gerrit-Owner: Rfaulk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to