Commit 1dd2804c authored by Michal Čihař's avatar Michal Čihař

Optimize dictionary import by using iterate_merge

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent f9e11291
...@@ -46,26 +46,28 @@ class DictionaryManager(models.Manager): ...@@ -46,26 +46,28 @@ class DictionaryManager(models.Manager):
ret = 0 ret = 0
# process all units # process all units
for unit in store.units: for dummy, unit in store.iterate_merge(False):
# We care only about translated things source = unit.get_source()
if not unit.istranslatable() or not unit.istranslated(): target = unit.get_target()
continue
# Ignore too long words # Ignore too long words
if len(unit.source) > 200 or len(unit.target) > 200: if len(source) > 200 or len(target) > 200:
continue continue
# Get object # Get object
word, created = self.get_or_create( word, created = self.get_or_create(
project=project, project=project,
language=language, language=language,
source=unit.source source=source,
defaults={
'target': target,
},
) )
# Already existing entry found # Already existing entry found
if not created: if not created:
# Same as current -> ignore # Same as current -> ignore
if unit.target == word.target: if target == word.target:
continue continue
if method == 'add': if method == 'add':
# Add word # Add word
...@@ -74,15 +76,13 @@ class DictionaryManager(models.Manager): ...@@ -74,15 +76,13 @@ class DictionaryManager(models.Manager):
action=Change.ACTION_DICTIONARY_UPLOAD, action=Change.ACTION_DICTIONARY_UPLOAD,
project=project, project=project,
language=language, language=language,
source=unit.source source=source,
target=target
) )
elif method != 'overwrite': elif method == 'overwrite':
# No overwriting or adding # Update word
continue word.target = target
word.save()
# Store word
word.target = unit.target
word.save()
ret += 1 ret += 1
......
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