Преглед на файлове

Get out of deadly inbound rel loop.

Stefano Cossu преди 7 години
родител
ревизия
0d6550647d
променени са 3 файла, в които са добавени 30 реда и са изтрити 20 реда
  1. 10 0
      doc/notes/performance.txt
  2. 1 1
      lakesuperior/store_layouts/ldp_rs/lmdb_store.py
  3. 19 19
      lakesuperior/store_layouts/ldp_rs/rsrc_centric_layout.py

+ 10 - 0
doc/notes/performance.txt

@@ -67,3 +67,13 @@ Database size: 422 Mb
 
 Retrieval of parent resource (11400 triples), pipe to /dev/null: 7.5"
 
+
+### After using triple methods rather than SPARQL for extract_imr
+
+25' running time
+0.155" per resource
+
+Database size: 523 Mb
+
+Retrieval of parent resource, pipe to /dev/null: 1.9"
+

+ 1 - 1
lakesuperior/store_layouts/ldp_rs/lmdb_store.py

@@ -212,7 +212,7 @@ class LmdbStore(Store):
     '''
     KEY_HASH_ALGO = 'sha1'
 
-    '''Separator byte. Used to join and plit individual term keys.'''
+    '''Separator byte. Used to join and split individual term keys.'''
     SEP_BYTE = b'\x00'
 
     DEFAULT_GRAPH_URI = URIRef('urn:fcrepo:default_graph')

+ 19 - 19
lakesuperior/store_layouts/ldp_rs/rsrc_centric_layout.py

@@ -232,23 +232,27 @@ class RsrcCentricLayout:
         if ver_uid:
             uid = self.snapshot_uid(uid, ver_uid)
 
-        import pdb; pdb.set_trace()
         graphs = {pfx[uid] for pfx in self.graph_ns_types.keys()}
+
+        # Exclude children: remove containment graphs.
         if not incl_children:
             graphs.remove(nsc['fcstruct'][uid])
 
         rsrc_graphs = [
-                self.store.triples((None, None, None), gr)
+                self.ds.graph(gr)
                 for gr in graphs]
         resultset = set(chain.from_iterable(rsrc_graphs))
 
+        gr = Graph()
+        gr += resultset
+
+        # Include inbound relationships.
         if incl_inbound and len(gr):
-            resultset += self.get_inbound_rel(nsc['fcres'][uid])
+            gr += self.get_inbound_rel(nsc['fcres'][uid])
 
-        gr = Graph()
         #self._logger.debug('Found resource: {}'.format(
         #        gr.serialize(format='turtle').decode('utf-8')))
-        gr += resultset
+
         rsrc = Resource(gr, nsc['fcres'][uid])
 
         if strict:
@@ -327,20 +331,16 @@ class RsrcCentricLayout:
 
         @param subj_uri Subject URI.
         '''
-        #import pdb; pdb.set_trace()
-        # Only search in non-historic graphs.
-        qry = '''
-        CONSTRUCT { ?s1 ?p1 ?s }
-        WHERE {
-          GRAPH ?g {
-            ?s1 ?p1 ?s .
-          }
-          GRAPH ?mg {
-            ?g foaf:primaryTopic ?s1 .
-          }
-        }
-        '''
-        return self._parse_construct(qry, init_bindings={'s': uri})
+        # Only return non-historic graphs.
+        meta_gr = self.ds.graph(META_GR_URI)
+        ptopic_uri = nsc['foaf'].primaryTopic
+
+        ib_rels = (
+            match[:3] for match in self.ds.quads((None, None, uri, None))
+            if set(meta_gr[ : ptopic_uri : match[0]])
+        )
+
+        yield from ib_rels
 
 
     def get_recursive(self, uid, predicate):