fix performance problem in relation registry
This commit is contained in:
parent
de06a8d30d
commit
bd9afff0bf
2 changed files with 17 additions and 4 deletions
|
@ -37,11 +37,16 @@ class Relation(Persistent):
|
||||||
|
|
||||||
order = 0
|
order = 0
|
||||||
relevance = 1.0
|
relevance = 1.0
|
||||||
|
fallback = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getPredicateName(cls):
|
def getPredicateName(cls):
|
||||||
return '%s.%s' % (cls.__module__, cls.__name__)
|
return '%s.%s' % (cls.__module__, cls.__name__)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ident(self):
|
||||||
|
return self.getPredicateName()
|
||||||
|
|
||||||
def validate(self, registry=None):
|
def validate(self, registry=None):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,7 @@ class RelationRegistry(Catalog):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
criteria[attr] = intids.getId(value)
|
criteria[attr] = intids.getId(value)
|
||||||
pn = example.getPredicateName()
|
pn = example.getPredicateName()
|
||||||
if pn:
|
if pn is not None:
|
||||||
criteria['relationship'] = pn
|
criteria['relationship'] = pn
|
||||||
for k in kw:
|
for k in kw:
|
||||||
# overwrite example fields with explicit values
|
# overwrite example fields with explicit values
|
||||||
|
@ -244,12 +244,20 @@ def getRelations(first=None, second=None, third=None, relationships=None):
|
||||||
if not relationships:
|
if not relationships:
|
||||||
return registry.query(**query)
|
return registry.query(**query)
|
||||||
else:
|
else:
|
||||||
result = set()
|
predicates = []
|
||||||
for r in relationships:
|
for r in relationships:
|
||||||
query['relationship'] = r
|
if hasattr(r, 'predicate'):
|
||||||
result.update(registry.query(**query))
|
predicates.append(r.predicate)
|
||||||
|
r.predicate = None
|
||||||
|
else:
|
||||||
|
predicates.append(r.getPredicateName())
|
||||||
|
result = registry.query(**query)
|
||||||
|
if predicates:
|
||||||
|
return [r for r in result
|
||||||
|
if r.ident in predicates or r.fallback in predicates]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def getRelationSingle(obj=None, relationship=None, forSecond=True):
|
def getRelationSingle(obj=None, relationship=None, forSecond=True):
|
||||||
""" Returns the one and only relation for first having relationship
|
""" Returns the one and only relation for first having relationship
|
||||||
or None if there is none.
|
or None if there is none.
|
||||||
|
|
Loading…
Add table
Reference in a new issue