Improved ZT event aggregation performance

This commit is contained in:
VakarisZ 2020-04-28 16:50:01 +03:00
parent 41ae125980
commit 1afbe3dea5
2 changed files with 2 additions and 6 deletions

View File

@ -12,7 +12,7 @@ class AggregateFinding(Finding):
:raises: Assertion error if this is used when there's more then one finding which fits the query - this is not :raises: Assertion error if this is used when there's more then one finding which fits the query - this is not
when this function should be used. when this function should be used.
""" """
existing_findings = Finding.objects(test=test, status=status) existing_findings = Finding.objects(test=test, status=status).exclude('events')
assert (len(existing_findings) < 2), "More than one finding exists for {}:{}".format(test, status) assert (len(existing_findings) < 2), "More than one finding exists for {}:{}".format(test, status)
if len(existing_findings) == 0: if len(existing_findings) == 0:
@ -20,7 +20,7 @@ class AggregateFinding(Finding):
else: else:
# Now we know for sure this is the only one # Now we know for sure this is the only one
orig_finding = existing_findings[0] orig_finding = existing_findings[0]
orig_finding.add_events(events) orig_finding.update(push_all__events=events)
orig_finding.save() orig_finding.save()

View File

@ -54,7 +54,3 @@ class Finding(Document):
finding.save() finding.save()
return finding return finding
def add_events(self, events):
# type: (list) -> None
self.events.extend(events)