Skip to content

Commit

Permalink
Merge pull request #42 from ternaustralia/edmond/regression-tern-voca…
Browse files Browse the repository at this point in the history
…bs-label

Only conditionally apply SPARQL service query based on namespace of URI
  • Loading branch information
edmondchuc authored Nov 7, 2022
2 parents 2b066f2 + c39fedf commit 6335fa4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/linkeddata_api/domain/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get(
}
?uri ?labelProperty ?label .
}
{% if uri.startswith('http://linked.data.gov.au/def/tern-cv/') %}
UNION {
SERVICE <https://graphdb.tern.org.au/repositories/tern_vocabs_core> {
BIND(<{{ uri }}> as ?uri)
Expand All @@ -50,6 +51,7 @@ def get(
?uri ?labelProperty ?label .
}
}
{% endif %}
}
LIMIT 1
"""
Expand Down Expand Up @@ -97,6 +99,7 @@ def _get_from_list_query(uris: list[str]) -> str:
}
?uri ?labelProperty ?label .
}
{% if uri.startswith('http://linked.data.gov.au/def/tern-cv/') %}
UNION {
SERVICE <https://graphdb.tern.org.au/repositories/tern_vocabs_core> {
BIND(<{{ uri }}> as ?uri)
Expand All @@ -111,6 +114,7 @@ def _get_from_list_query(uris: list[str]) -> str:
?uri ?labelProperty ?label .
}
}
{% endif %}
}
LIMIT 1
}
Expand Down
33 changes: 23 additions & 10 deletions src/linkeddata_api/log_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ def log_time(func):

@wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()

callerframerecord = inspect.stack()[1]
frame = callerframerecord[0]
info = inspect.getframeinfo(frame)

logger.debug(
"%s ran in %ss",
f"{info.filename}:{info.lineno}",
round(end - start, 2),
)
return result
logger.debug("Running %s", f"{info.filename}:{info.lineno}")

start = time.time()
try:
result = func(*args, **kwargs)
end = time.time()

logger.debug(
"%s ran in %ss",
f"{info.filename}:{info.lineno}",
round(end - start, 2),
)
return result
except Exception as err:
logger.error(
"Error occurred running %s with args: %s kwargs: %s. Message: %s",
f"{info.filename}:{info.lineno}",
str(args),
str(kwargs),
err,
)

raise err

return wrapper

0 comments on commit 6335fa4

Please sign in to comment.