fix performance problem in relation registry
This commit is contained in:
parent
e0ea52cb1d
commit
c9ee6d1aac
6 changed files with 47 additions and 13 deletions
|
@ -647,6 +647,13 @@
|
|||
factory="loops.browser.form.EditConcept"
|
||||
permission="zope.View" />
|
||||
|
||||
<page
|
||||
name="test.html"
|
||||
for="loops.interfaces.INode"
|
||||
class="loops.browser.node.TestView"
|
||||
permission="zope.View" />
|
||||
|
||||
|
||||
<!-- inner HTML views -->
|
||||
|
||||
<page
|
||||
|
|
|
@ -1006,3 +1006,18 @@ def getViewConfiguration(context, request):
|
|||
viewAnnotations = request.annotations.get('loops.view', {})
|
||||
return dict(skinName=viewAnnotations.get('skinName'),
|
||||
options=viewAnnotations.get('options'))
|
||||
|
||||
|
||||
|
||||
class TestView(NodeView):
|
||||
|
||||
def __call__(self):
|
||||
print '*** begin'
|
||||
for i in range(500):
|
||||
#x = util.getObjectForUid('1994729849')
|
||||
x = util.getObjectForUid('2018653366')
|
||||
self.c = list(x.getChildren())
|
||||
#self.c = list(x.getChildren([self.defaultPredicate]))
|
||||
print '*** end', len(self.c)
|
||||
return 'done'
|
||||
|
||||
|
|
18
concept.py
18
concept.py
|
@ -63,6 +63,8 @@ from loops.view import TargetRelation
|
|||
|
||||
class BaseRelation(DyadicRelation):
|
||||
|
||||
fallback = '*'
|
||||
|
||||
def __init__(self, first, second, predicate=None):
|
||||
super(BaseRelation, self).__init__(first, second)
|
||||
if predicate is None:
|
||||
|
@ -72,10 +74,16 @@ class BaseRelation(DyadicRelation):
|
|||
self.predicate = predicate
|
||||
|
||||
def getPredicateName(self):
|
||||
if self.predicate is None:
|
||||
return None
|
||||
baseName = super(BaseRelation, self).getPredicateName()
|
||||
id = util.getUidForObject(self.predicate)
|
||||
return '.'.join((baseName, id))
|
||||
|
||||
@property
|
||||
def ident(self):
|
||||
return self.predicate
|
||||
|
||||
# Problem with reindex catalog, needs __parent__ - but this does not help:
|
||||
#__parent__ = None
|
||||
#@property
|
||||
|
@ -89,12 +97,16 @@ class ConceptRelation(BaseRelation):
|
|||
"""
|
||||
implements(IConceptRelation)
|
||||
|
||||
fallback = 'c*'
|
||||
|
||||
|
||||
class ResourceRelation(BaseRelation):
|
||||
""" A relation between a concept and a resource object.
|
||||
"""
|
||||
implements(IConceptRelation)
|
||||
|
||||
fallback = 'r*'
|
||||
|
||||
|
||||
# concept
|
||||
|
||||
|
@ -182,7 +194,7 @@ class Concept(Contained, Persistent):
|
|||
|
||||
def getChildRelations(self, predicates=None, child=None, sort='default',
|
||||
noSecurityCheck=False):
|
||||
predicates = predicates is None and ['*'] or predicates
|
||||
predicates = predicates is None and ['c*'] or predicates
|
||||
relationships = [ConceptRelation(self, None, p) for p in predicates]
|
||||
if sort == 'default':
|
||||
sort = lambda x: (x.order, (x.second.title and x.second.title.lower()))
|
||||
|
@ -196,7 +208,7 @@ class Concept(Contained, Persistent):
|
|||
|
||||
def getParentRelations (self, predicates=None, parent=None, sort='default',
|
||||
noSecurityCheck=False):
|
||||
predicates = predicates is None and ['*'] or predicates
|
||||
predicates = predicates is None and ['c*'] or predicates
|
||||
relationships = [ConceptRelation(None, self, p) for p in predicates]
|
||||
if sort == 'default':
|
||||
sort = lambda x: (x.first.title and x.first.title.lower())
|
||||
|
@ -277,7 +289,7 @@ class Concept(Contained, Persistent):
|
|||
noSecurityCheck=False):
|
||||
if resource is not None:
|
||||
resource = getMaster(resource)
|
||||
predicates = predicates is None and ['*'] or predicates
|
||||
predicates = predicates is None and ['r*'] or predicates
|
||||
relationships = [ResourceRelation(self, None, p) for p in predicates]
|
||||
if sort == 'default':
|
||||
sort = lambda x: (x.order, x.second.title.lower())
|
||||
|
|
|
@ -47,7 +47,7 @@ Type- and text-based queries
|
|||
>>> from loops.expert import query
|
||||
>>> qu = query.Title('ty*')
|
||||
>>> list(qu.apply())
|
||||
[0, 1, 68]
|
||||
[0, 2, 68]
|
||||
|
||||
>>> qu = query.Type('loops:*')
|
||||
>>> len(list(qu.apply()))
|
||||
|
@ -59,7 +59,7 @@ Type- and text-based queries
|
|||
|
||||
>>> qu = query.Type('loops:concept:predicate') & query.Title('t*')
|
||||
>>> list(qu.apply())
|
||||
[1, 29]
|
||||
[2, 29]
|
||||
|
||||
State-based queries
|
||||
-------------------
|
||||
|
|
|
@ -201,7 +201,7 @@ class Resource(Image, Contained):
|
|||
|
||||
def getConceptRelations (self, predicates=None, concept=None, sort='default',
|
||||
noSecurityCheck=False):
|
||||
predicates = predicates is None and ['*'] or predicates
|
||||
predicates = predicates is None and ['r*'] or predicates
|
||||
obj = getMaster(self)
|
||||
relationships = [ResourceRelation(None, obj, p) for p in predicates]
|
||||
if sort == 'default':
|
||||
|
|
|
@ -53,16 +53,16 @@ domain concept (if present, otherwise the top-level type concept):
|
|||
['children', 'description', 'id', 'name', 'parents', 'resources',
|
||||
'title', 'type', 'viewName']
|
||||
>>> startObj['id'], startObj['name'], startObj['title'], startObj['type']
|
||||
('4', u'domain', u'Domain', '0')
|
||||
('3', u'domain', u'Domain', '0')
|
||||
|
||||
There are a few standard objects we can retrieve directly:
|
||||
|
||||
>>> defaultPred = xrf.getDefaultPredicate()
|
||||
>>> defaultPred['id'], defaultPred['name']
|
||||
('3', u'standard')
|
||||
('14', u'standard')
|
||||
>>> typePred = xrf.getTypePredicate()
|
||||
>>> typePred['id'], typePred['name']
|
||||
('1', u'hasType')
|
||||
('2', u'hasType')
|
||||
>>> typeConcept = xrf.getTypeConcept()
|
||||
>>> typeConcept['id'], typeConcept['name']
|
||||
('0', u'type')
|
||||
|
@ -80,12 +80,12 @@ applied in an explicit assignment.
|
|||
|
||||
We can also retrieve a certain object by its id or its name:
|
||||
|
||||
>>> obj2 = xrf.getObjectById('4')
|
||||
>>> obj2 = xrf.getObjectById('3')
|
||||
>>> obj2['id'], obj2['name']
|
||||
('4', u'domain')
|
||||
('3', u'domain')
|
||||
>>> textdoc = xrf.getObjectByName(u'textdocument')
|
||||
>>> textdoc['id'], textdoc['name']
|
||||
('10', u'textdocument')
|
||||
('9', u'textdocument')
|
||||
|
||||
All methods that retrieve one object also returns its children and parents:
|
||||
|
||||
|
@ -117,7 +117,7 @@ We can also retrieve children and parents explicitely:
|
|||
[u'competence', u'customer', u'domain', u'file', u'note', u'person',
|
||||
u'predicate', u'task', u'textdocument', u'topic', u'training', u'type']
|
||||
|
||||
>>> pa = xrf.getParents('6')
|
||||
>>> pa = xrf.getParents('5')
|
||||
>>> len(pa)
|
||||
1
|
||||
>>> pa[0]['name']
|
||||
|
|
Loading…
Add table
Reference in a new issue