diff --git a/light9/rdfdb/currentstategraphapi.py b/light9/rdfdb/currentstategraphapi.py --- a/light9/rdfdb/currentstategraphapi.py +++ b/light9/rdfdb/currentstategraphapi.py @@ -3,6 +3,18 @@ from rdflib import ConjunctiveGraph 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 @@ class CurrentStateGraphApi(object): # 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