Changeset - 7a85229d07a0
[Not reviewed]
default
0 1 0
Drew Perttula - 8 years ago 2017-05-11 05:20:15
drewp@bigasterisk.com
currentgraphstate now returns readonly (not actually snapshotted) view of the graph, not a copy
Ignore-this: 7db0291740fe8dee0ad25b24571b171b
1 file changed with 21 insertions and 6 deletions:
0 comments (0 inline, 0 general)
light9/rdfdb/currentstategraphapi.py
Show inline comments
 
@@ -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
0 comments (0 inline, 0 general)