Mercurial > code > home > repos > light9
changeset 1536:7a85229d07a0
currentgraphstate now returns readonly (not actually snapshotted) view of the graph, not a copy
Ignore-this: 7db0291740fe8dee0ad25b24571b171b
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Thu, 11 May 2017 05:20:15 +0000 |
parents | 04f2e93f04e3 |
children | b95b97177de6 |
files | light9/rdfdb/currentstategraphapi.py |
diffstat | 1 files changed, 21 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/rdfdb/currentstategraphapi.py Wed May 10 07:13:27 2017 +0000 +++ b/light9/rdfdb/currentstategraphapi.py Thu May 11 05:20:15 2017 +0000 @@ -3,6 +3,18 @@ from light9.rdfdb.rdflibpatch import contextsForStatement as rp_contextsForStatement log = logging.getLogger("currentstate") +class ReadOnlyConjunctiveGraph(object): + """similar to rdflib's ReadOnlyGraphAggregate but takes one CJ in, instead + of a bunch of Graphs""" + def __init__(self, graph): + self.graph = graph + + def __getattr__(self, attr): + if attr in ['subjects', 'value', 'objects', 'triples']: # not complete + return getattr(self.graph, attr) + raise TypeError("can't access %r of read-only graph" % attr) + + class CurrentStateGraphApi(object): """ mixin for SyncedGraph, separated here because these methods work together @@ -25,13 +37,16 @@ # done. Typical usage will do some reads on this graph # before moving on to writes. - t1 = time.time() - g = ConjunctiveGraph() - for s,p,o,c in self._graph.quads(tripleFilter): - g.store.add((s,p,o), c) + if 1: + g = ReadOnlyConjunctiveGraph(self._graph) + else: + t1 = time.time() + g = ConjunctiveGraph() + for s,p,o,c in self._graph.quads(tripleFilter): + g.store.add((s,p,o), c) - if tripleFilter == (None, None, None): - self2.logThisCopy(g, time.time() - t1) + if tripleFilter == (None, None, None): + self2.logThisCopy(g, time.time() - t1) g.contextsForStatement = lambda t: contextsForStatementNoWildcards(g, t) return g