Record query row count
This commit is contained in:
parent
1badd35362
commit
48fbe6c8f5
|
@ -110,6 +110,7 @@ class WikidataQuery(Base):
|
|||
status_code = Column(Integer)
|
||||
error_text = Column(String)
|
||||
query_template = Column(String)
|
||||
row_count = Column(Integer)
|
||||
|
||||
@property
|
||||
def duration(self):
|
||||
|
|
|
@ -35,7 +35,11 @@ def run_from_template_with_cache(template_name, cache_name=None, **context):
|
|||
query = render_template(template_name, **context)
|
||||
return run_query_with_cache(query, name=cache_name, query_template=template_name)
|
||||
|
||||
def run_query(query, query_template=None):
|
||||
def run_query(query, **kwargs):
|
||||
r, db_query = record_query(query, **kwargs)
|
||||
return r
|
||||
|
||||
def record_query(query, query_template=None):
|
||||
params = {'query': query, 'format': 'json'}
|
||||
start = datetime.utcnow()
|
||||
|
||||
|
@ -58,7 +62,7 @@ def run_query(query, query_template=None):
|
|||
database.session.commit()
|
||||
|
||||
assert r.status_code == 200
|
||||
return r
|
||||
return r, db_query
|
||||
|
||||
def md5_query(query):
|
||||
''' generate the md5 hexdigest of a SPARQL query '''
|
||||
|
@ -73,11 +77,13 @@ def run_query_with_cache(q, name=None, query_template=None):
|
|||
if isinstance(from_cache, dict) and from_cache.get('query') == q:
|
||||
return from_cache['bindings']
|
||||
|
||||
r = run_query(q, query_template=query_template)
|
||||
r, db_query = record_query(q, query_template=query_template)
|
||||
bindings = r.json()['results']['bindings']
|
||||
json.dump({'query': q, 'bindings': bindings},
|
||||
open(filename, 'w'), indent=2)
|
||||
|
||||
db_query.row_count = len(bindings)
|
||||
database.session.commit()
|
||||
return bindings
|
||||
|
||||
def format_time(row_time, row_timeprecision):
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<div class="col-1"></div>
|
||||
<div class="col-2">template</div>
|
||||
<div class="col-2">when</div>
|
||||
<div class="col-1">rows</div>
|
||||
<div class="col-2">time</div>
|
||||
<div class="col">options</div>
|
||||
</div>
|
||||
|
@ -33,6 +34,10 @@
|
|||
{{ obj.start_time.strftime('%Y %b %d %H:%M') }}
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
{{ obj.row_count if obj.row_count is not none else '' }}
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
{% if obj.end_time %}
|
||||
{{ obj.display_seconds }} seconds
|
||||
|
|
Loading…
Reference in a new issue