Commit 28fbad38 authored by Michal Čihař's avatar Michal Čihař

Move flushing code to search module

parent ab18292c
...@@ -67,6 +67,15 @@ def create_index(sender=None, **kwargs): ...@@ -67,6 +67,15 @@ def create_index(sender=None, **kwargs):
create_source_index() create_source_index()
def flush_index():
'''
Flushes any possibly buffered writes to index.
'''
FULLTEXT_INDEX._source_writer.commit()
for lang in FULLTEXT_INDEX._target_writer:
FULLTEXT_INDEX._target_writer[lang].commit()
def update_index(units, source_units = None): def update_index(units, source_units = None):
''' '''
Updates fulltext index for given set of units. Updates fulltext index for given set of units.
......
...@@ -24,7 +24,7 @@ Tests for management commands. ...@@ -24,7 +24,7 @@ Tests for management commands.
from trans.tests.models import RepoTestCase from trans.tests.models import RepoTestCase
from django.core.management import call_command from django.core.management import call_command
from trans.search import FULLTEXT_INDEX from trans.search import flush_index
class ImportProjectTest(RepoTestCase): class ImportProjectTest(RepoTestCase):
...@@ -117,10 +117,8 @@ class PeriodicTest(RepoTestCase): ...@@ -117,10 +117,8 @@ class PeriodicTest(RepoTestCase):
def test_update_index(self): def test_update_index(self):
# Flush possible caches # Flush possible caches
FULLTEXT_INDEX._source_writer.commit() flush_index()
for lang in FULLTEXT_INDEX._target_writer: # Test the command
FULLTEXT_INDEX._target_writer[lang].commit()
call_command( call_command(
'update_index' 'update_index'
) )
...@@ -200,9 +198,7 @@ class RebuildIndexTest(CheckGitTest): ...@@ -200,9 +198,7 @@ class RebuildIndexTest(CheckGitTest):
def setUp(self): def setUp(self):
super(RebuildIndexTest, self).setUp() super(RebuildIndexTest, self).setUp()
# Flush possible caches # Flush possible caches
FULLTEXT_INDEX._source_writer.commit() flush_index()
for lang in FULLTEXT_INDEX._target_writer:
FULLTEXT_INDEX._target_writer[lang].commit()
def test_all_clean(self): def test_all_clean(self):
self.do_test( self.do_test(
......
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