Improve performance on trust deletion

During a trust deletion, the backend will fetch all trust by the same
trustor and look for redelegations to be deleted as well. If you have
a considerable amount of trusts that call becomes expensive. Just by
pushing this filter into the backend, the response time for the api call
just depends on the number of redelegations for that trust.

Change-Id: Id3a820fca0bb20561ba031797d2b0fb96ba1f78d
Closes-Bug: #1935840
This commit is contained in:
Jose Castro Leon 2021-07-13 11:00:58 +02:00
parent cf5f1e5651
commit 23477a13ab
No known key found for this signature in database
GPG Key ID: C764DDA562D30FD5
3 changed files with 15 additions and 11 deletions

View File

@ -48,7 +48,7 @@ class TrustDriverBase(object, metaclass=abc.ABCMeta):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_trusts_for_trustor(self, trustor):
def list_trusts_for_trustor(self, trustor, redelegated_trust_id=None):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod

View File

@ -171,11 +171,15 @@ class Trust(base.TrustDriverBase):
filter_by(trustee_user_id=trustee_user_id))
return [trust_ref.to_dict() for trust_ref in trusts]
def list_trusts_for_trustor(self, trustor_user_id):
def list_trusts_for_trustor(self, trustor_user_id,
redelegated_trust_id=None):
with sql.session_for_read() as session:
trusts = (session.query(TrustModel).
filter_by(deleted_at=None).
filter_by(trustor_user_id=trustor_user_id))
if redelegated_trust_id:
trusts = trusts.filter_by(
redelegated_trust_id=redelegated_trust_id)
return [trust_ref.to_dict() for trust_ref in trusts]
@sql.handle_conflicts(conflict_type='trust')

View File

@ -194,17 +194,17 @@ class Manager(manager.Manager):
"""
trust = self.driver.get_trust(trust_id)
trusts = self.driver.list_trusts_for_trustor(
trust['trustor_user_id'])
trust['trustor_user_id'],
redelegated_trust_id=trust_id)
for t in trusts:
if t.get('redelegated_trust_id') == trust_id:
# recursive call to make sure all notifications are sent
try:
self.delete_trust(t['id'])
except exception.TrustNotFound: # nosec
# if trust was deleted by concurrent process
# consistency must not suffer
pass
# recursive call to make sure all notifications are sent
try:
self.delete_trust(t['id'])
except exception.TrustNotFound: # nosec
# if trust was deleted by concurrent process
# consistency must not suffer
pass
# end recursion
self.driver.delete_trust(trust_id)