diff options
author | Florian Ludwig <f.ludwig@greyrook.com> | 2020-10-24 10:35:12 +0200 |
---|---|---|
committer | Florian Ludwig <f.ludwig@greyrook.com> | 2020-10-24 10:35:12 +0200 |
commit | 63b756f2e4ab8f570103debc88b3dcbbaae577f6 (patch) | |
tree | a061cf8619372ca1910dfcdb4d318b51592a62d7 | |
parent | b35956e07885ff147991c7dfd31039bbea7ca5e0 (diff) | |
download | rdflib-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.py | 9 |
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, |