Commit e69e62fc authored by Michal Čihař's avatar Michal Čihař

Update source index only when needed

parent 83dd5a3b
......@@ -36,7 +36,7 @@ class Command(BaseCommand):
return
with FULLTEXT_INDEX.source_writer(buffered = False) as writer:
for update in base.iterator():
for update in base.filter(source = True).iterator():
Unit.objects.add_to_source_index(
update.unit.checksum,
update.unit.source,
......
......@@ -271,23 +271,24 @@ class UnitManager(models.Manager):
target = unicode(target),
)
def add_to_index(self, unit):
def add_to_index(self, unit, source = True):
'''
Updates/Adds to all indices given unit.
'''
if settings.OFFLOAD_INDEXING:
from weblate.trans.models import IndexUpdate
IndexUpdate.objects.get_or_create(unit = unit)
IndexUpdate.objects.get_or_create(unit = unit, source = source)
return
writer_target = FULLTEXT_INDEX.target_writer(unit.translation.language.code)
writer_source = FULLTEXT_INDEX.source_writer()
self.add_to_source_index(
unit.checksum,
unit.source,
unit.context,
writer_source)
if source:
self.add_to_source_index(
unit.checksum,
unit.source,
unit.context,
writer_source)
self.add_to_target_index(
unit.checksum,
unit.target,
......
......@@ -2159,6 +2159,7 @@ class Unit(models.Model):
# Pop parameter indicating that we don't have to process content
same_content = kwargs.pop('same_content', False)
same_fuzzy = kwargs.pop('same_fuzzy', False)
force_insert = kwargs.get('force_insert', False)
# Actually save the unit
super(Unit, self).save(*args, **kwargs)
......@@ -2166,9 +2167,14 @@ class Unit(models.Model):
# Update checks if content or fuzzy flag has changed
if not same_content or not same_fuzzy:
self.check()
# Update fulltext index if content has changed
if not same_content:
Unit.objects.add_to_index(self)
# Update fulltext index if content has changed or this is a new unit
if force_insert:
# New unit, need to update both source and target index
Unit.objects.add_to_index(self, True)
else:
# We only update target index here
Unit.objects.add_to_index(self, False)
def get_location_links(self):
'''
......@@ -2469,6 +2475,7 @@ class Change(models.Model):
class IndexUpdate(models.Model):
unit = models.ForeignKey(Unit)
source = models.BooleanField(default = True)
def get_version_module(module, name, url):
try:
......
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