Commit 5cbe3e34 authored by Michal Čihař's avatar Michal Čihař

Split translations update to more transactions

Generating huge transaction just pushes too much on the database server.
Also we want to commit changes soon as we're already sending
notifications for changes.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 774a763a
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from django.db import models from django.db import models, transaction
from django.utils.translation import ugettext as _, ugettext_lazy from django.utils.translation import ugettext as _, ugettext_lazy
from django.core.mail import mail_admins from django.core.mail import mail_admins
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
...@@ -966,40 +966,42 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -966,40 +966,42 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
matches = self.get_mask_matches() matches = self.get_mask_matches()
language_re = re.compile(self.language_regex) language_re = re.compile(self.language_regex)
for pos, path in enumerate(matches): for pos, path in enumerate(matches):
code = self.get_lang_code(path) with transaction.atomic():
if langs is not None and code not in langs: code = self.get_lang_code(path)
self.log_info('skipping %s', path) if langs is not None and code not in langs:
continue self.log_info('skipping %s', path)
if not language_re.match(code): continue
self.log_info('skipping language %s', code) if not language_re.match(code):
continue self.log_info('skipping language %s', code)
continue
self.log_info( self.log_info(
'checking %s (%s) [%d/%d]', 'checking %s (%s) [%d/%d]',
path, path,
code, code,
pos + 1, pos + 1,
len(matches) len(matches)
) )
lang = Language.objects.auto_get_or_create(code=code) lang = Language.objects.auto_get_or_create(code=code)
if lang.code in languages: if lang.code in languages:
self.log_error('duplicate language found: %s', lang.code) self.log_error('duplicate language found: %s', lang.code)
continue continue
translation = Translation.objects.check_sync( translation = Translation.objects.check_sync(
self, lang, code, path, force, request=request self, lang, code, path, force, request=request
) )
translations.add(translation.id) translations.add(translation.id)
languages.add(lang.code) languages.add(lang.code)
# Delete possibly no longer existing translations # Delete possibly no longer existing translations
if langs is None: if langs is None:
todelete = self.translation_set.exclude(id__in=translations) todelete = self.translation_set.exclude(id__in=translations)
if todelete.exists(): if todelete.exists():
self.log_info( with transaction.atomic():
'removing stale translations: %s', self.log_info(
','.join([trans.language.code for trans in todelete]) 'removing stale translations: %s',
) ','.join([trans.language.code for trans in todelete])
todelete.delete() )
todelete.delete()
# Process linked repos # Process linked repos
for subproject in self.get_linked_childs(): for subproject in self.get_linked_childs():
......
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