Skip to content
Snippets Groups Projects
Verified Commit 95e69cc4 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

ADD etag to query cache feature

parent 21a79809
No related branches found
No related tags found
1 merge request!3F fsm
...@@ -3661,6 +3661,7 @@ class Query(): ...@@ -3661,6 +3661,7 @@ class Query():
self.flags = dict() self.flags = dict()
self.messages = _Messages() self.messages = _Messages()
self.cached = None self.cached = None
self.etag = None
if isinstance(q, etree._Element): if isinstance(q, etree._Element):
self.q = q.get("string") self.q = q.get("string")
...@@ -3670,6 +3671,7 @@ class Query(): ...@@ -3670,6 +3671,7 @@ class Query():
self.cached = False self.cached = False
else: else:
self.cached = q.get("cached").lower() == "true" self.cached = q.get("cached").lower() == "true"
self.etag = q.get("etag")
for m in q: for m in q:
if m.tag.lower() == 'warning' or m.tag.lower() == 'error': if m.tag.lower() == 'warning' or m.tag.lower() == 'error':
...@@ -3714,6 +3716,7 @@ class Query(): ...@@ -3714,6 +3716,7 @@ class Query():
cresp = Container._response_to_entities(http_response) cresp = Container._response_to_entities(http_response)
self.results = cresp.query.results self.results = cresp.query.results
self.cached = cresp.query.cached self.cached = cresp.query.cached
self.etag = cresp.query.etag
if self.q.lower().startswith('count') and len(cresp) == 0: if self.q.lower().startswith('count') and len(cresp) == 0:
# this was a count query # this was a count query
......
...@@ -26,20 +26,23 @@ import caosdb as db ...@@ -26,20 +26,23 @@ import caosdb as db
def test_query_parsing(): def test_query_parsing():
s = '<Query string="FIND bla" results="0" cached="true"/>' s = '<Query string="FIND bla" results="0" cached="true" etag="asdf"/>'
q = db.Query(etree.fromstring(s)) q = db.Query(etree.fromstring(s))
assert q.q == "FIND bla" assert q.q == "FIND bla"
assert q.results == 0 assert q.results == 0
assert q.cached is True assert q.cached is True
assert q.etag == "asdf"
s = '<Query string="COUNT bla" results="1" cached="false"/>' s = '<Query string="COUNT bla" results="1" cached="false" etag="asdf"/>'
q = db.Query(etree.fromstring(s)) q = db.Query(etree.fromstring(s))
assert q.q == "COUNT bla" assert q.q == "COUNT bla"
assert q.results == 1 assert q.results == 1
assert q.cached is False assert q.cached is False
assert q.etag == "asdf"
s = '<Query string="COUNT blub" results="4"/>' s = '<Query string="COUNT blub" results="4"/>'
q = db.Query(etree.fromstring(s)) q = db.Query(etree.fromstring(s))
assert q.q == "COUNT blub" assert q.q == "COUNT blub"
assert q.results == 4 assert q.results == 4
assert q.cached is False assert q.cached is False
assert q.etag is None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment