Skip to content

Commit

Permalink
stub out query handling logic in mvt, re #10502
Browse files Browse the repository at this point in the history
  • Loading branch information
whatisgalen committed Aug 23, 2024
1 parent df10522 commit 100666d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions arches/app/views/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import importlib
import json
import logging
Expand Down Expand Up @@ -361,6 +362,11 @@ def get(self, request, nodeid, zoom, x, y):
search_geom_count = 0
config = node.config
cache_key = MVT.create_mvt_cache_key(node, zoom, x, y, request.user)
# to modify this for a search-layer, you would have to:
# 1. include a query string
# 2. execute the query with a particular filter added so that only ids get returned
# 3. create a special layer in map.js that uses the search-layer
# 4. send the results ids to the tile query
tile = cache.get(cache_key)
if tile is None:
resource_ids = get_restricted_instances(request.user, allresources=True)
Expand Down Expand Up @@ -504,6 +510,35 @@ def get(self, request, nodeid, zoom, x, y):
def create_mvt_cache_key(node, zoom, x, y, user):
return f"mvt_{str(node.nodeid)}_{zoom}_{x}_{y}_{user.id}"

def create_searchresults_cache_key(request, search_query, **kwargs):
"""
method to create a hash cache key
cleans/sorts the searchquery before converting to string in order to normalize
kwargs:
- dict: search_query - contains search query filters/parameters
"""

user_proxy = (
request.user.username
if request.user.username == "anonymous"
else str(request.user.id)
)
search_query_string = "".join(
[k + str(v) for k, v in sorted(search_query.items())]
)

search_query_string = search_query_string.strip()
snapshot = ""
# snapshot = str(
# EditLog.objects.all().count()
# ) # proxy for db state (temporal)
b = bytearray()
b.extend((search_query_string + snapshot + user_proxy).encode())
search_query_cache_key_hash = hashlib.sha1(b)
search_query_cache_key_hash = search_query_cache_key_hash.hexdigest()

return search_query_cache_key_hash


@method_decorator(csrf_exempt, name="dispatch")
class Graphs(APIBase):
Expand Down

0 comments on commit 100666d

Please sign in to comment.