summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Ludwig <f.ludwig@greyrook.com>2020-10-24 10:35:12 +0200
committerFlorian Ludwig <f.ludwig@greyrook.com>2020-10-24 10:35:12 +0200
commit63b756f2e4ab8f570103debc88b3dcbbaae577f6 (patch)
treea061cf8619372ca1910dfcdb4d318b51592a62d7
parentb35956e07885ff147991c7dfd31039bbea7ca5e0 (diff)
downloadrdflib-63b756f2e4ab8f570103debc88b3dcbbaae577f6.tar.gz
Lazy store current time in sparql query context
This improves performance when doing a lot of small queries.
-rw-r--r--rdflib/plugins/sparql/sparql.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/rdflib/plugins/sparql/sparql.py b/rdflib/plugins/sparql/sparql.py
index f24aa564..43aee3ed 100644
--- a/rdflib/plugins/sparql/sparql.py
+++ b/rdflib/plugins/sparql/sparql.py
@@ -223,7 +223,6 @@ class FrozenBindings(FrozenDict):
class QueryContext(object):
-
"""
Query context - passed along when evaluating the query
"""
@@ -245,10 +244,16 @@ class QueryContext(object):
self.graph = graph
self.prologue = None
- self.now = datetime.datetime.now(isodate.tzinfo.UTC)
+ self._now = None
self.bnodes = collections.defaultdict(BNode)
+ @property
+ def now(self) -> datetime.datetime:
+ if self._now is None:
+ self._now = datetime.datetime.now(isodate.tzinfo.UTC)
+ return self._now
+
def clone(self, bindings=None):
r = QueryContext(
self._dataset if self._dataset is not None else self.graph,