Commit 55e05981 authored by Michal Čihař's avatar Michal Čihař

Update failing checks flag only if there was a change

Otherwise we just waste resources on checking that there is no change.
parent 6c8146ff
...@@ -802,14 +802,18 @@ class Unit(models.Model): ...@@ -802,14 +802,18 @@ class Unit(models.Model):
''' '''
from trans.models.unitdata import Check from trans.models.unitdata import Check
if len(source) == 0 and len(target) == 0: if len(source) == 0 and len(target) == 0:
return return False
Check.objects.filter( todelete = Check.objects.filter(
checksum=self.checksum, checksum=self.checksum,
project=self.translation.subproject.project project=self.translation.subproject.project
).filter( ).filter(
(Q(language=self.translation.language) & Q(check__in=target)) | (Q(language=self.translation.language) & Q(check__in=target)) |
(Q(language=None) & Q(check__in=source)) (Q(language=None) & Q(check__in=source))
).delete() )
if todelete.exists():
todelete.delete()
return True
return False
def checks(self): def checks(self):
''' '''
...@@ -907,7 +911,7 @@ class Unit(models.Model): ...@@ -907,7 +911,7 @@ class Unit(models.Model):
if not same_source.exists(): if not same_source.exists():
if checks.exists(): if checks.exists():
checks.delete() checks.delete()
self.update_has_failing_check(True, True) self.update_has_failing_check(True)
return return
# If there is no consistency checking, we can return # If there is no consistency checking, we can return
...@@ -961,13 +965,15 @@ class Unit(models.Model): ...@@ -961,13 +965,15 @@ class Unit(models.Model):
# Delete no longer failing checks # Delete no longer failing checks
if cleanup_checks: if cleanup_checks:
self.cleanup_checks(old_source_checks, old_target_checks) was_change |= self.cleanup_checks(old_source_checks, old_target_checks)
was_change = True
# Update failing checks flag # Update failing checks flag
self.update_has_failing_check(was_change, True) if was_change:
self.update_has_failing_check(True)
elif is_new:
self.update_has_failing_check(False)
def update_has_failing_check(self, was_change, recurse=False): def update_has_failing_check(self, recurse=False):
''' '''
Updates flag counting failing checks. Updates flag counting failing checks.
''' '''
...@@ -984,12 +990,11 @@ class Unit(models.Model): ...@@ -984,12 +990,11 @@ class Unit(models.Model):
# Invalidate checks cache if there was any change # Invalidate checks cache if there was any change
# (avove code cares only about whether there is failing check # (avove code cares only about whether there is failing check
# while here we care about any changed in checks) # while here we care about any changed in checks)
if was_change:
self.translation.invalidate_cache() self.translation.invalidate_cache()
if recurse: if recurse:
for unit in Unit.objects.same(self).exclude(id=self.id): for unit in Unit.objects.same(self).exclude(id=self.id):
unit.update_has_failing_check(was_change, False) unit.update_has_failing_check(False)
def update_has_suggestion(self): def update_has_suggestion(self):
''' '''
......
...@@ -319,7 +319,7 @@ class Check(models.Model, RelatedUnitMixin): ...@@ -319,7 +319,7 @@ class Check(models.Model, RelatedUnitMixin):
# Update related unit flags # Update related unit flags
for unit in self.get_related_units(): for unit in self.get_related_units():
unit.update_has_failing_check(True, False) unit.update_has_failing_check(False)
class IndexUpdate(models.Model): class IndexUpdate(models.Model):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment