Browse Source

include chart name in hash instead of using person

Daniel Sheffield 1 year ago
parent
commit
0b19eac707
3 changed files with 8 additions and 5 deletions
  1. 1 1
      app/rest/pyapi.py
  2. 5 2
      app/rest/route_decorators.py
  3. 2 2
      app/rest/trend.py

+ 1 - 1
app/rest/pyapi.py

@@ -82,7 +82,7 @@ def query_to_form(query):
 
 def key_to_form(key):
     query, _ = key
-    return query_to_form(query)
+    return query_to_form(query.split('?', 1)[-1])
 
 
 def iter_page(page):

+ 5 - 2
app/rest/route_decorators.py

@@ -37,7 +37,10 @@ def _cache_decorator(func: Callable, query_cache: QueryCache = None, page_cache:
     def wrap(*args, **kwargs):
         _, _, path, *_ = request.urlparts
         
+        endpoint = path.split('/', 2)[-1]
+
         query, _hash = normalize_query(request.params)
+        query = f"{endpoint}?{query}"
         if not _hash:
             _hashInt = get_hash(query)
             _hash = hash_to_base32(_hashInt)
@@ -60,8 +63,8 @@ def _cache_decorator(func: Callable, query_cache: QueryCache = None, page_cache:
             if cached and len(cached) > 2000:
                 return redirect(f"{path}?hash={_hash}")
 
-            if cached and request.query_string != cached:
-                return redirect(f"{path}?{cached}")
+            if cached and f"{endpoint}?{request.query_string}" != cached:
+                return redirect(cached)
 
         return func((cached, key[1]), page_cache, *args, **kwargs)
     return wrap

+ 2 - 2
app/rest/trend.py

@@ -50,8 +50,8 @@ plot_style = {
     "savefig.edgecolor": "#7f7f7f",
 }
 
-def get_data(query_manager: QueryManager, unit=None, **kwargs) -> pd.DataFrame:
-    d = pd.DataFrame(query_manager.get_historic_prices_data(unit, **kwargs))
+def get_data(query_manager: QueryManager, unit=None, **kwargs) -> DataFrame:
+    d = DataFrame(query_manager.get_historic_prices_data(unit, **kwargs))
     if d.empty:
         return d
     d['ts_month'] = d['ts_raw'].apply(lambda x: date(x.date().year, x.date().month,1))