File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ def __getitem__(self, key):
93
93
return self ._connections [key ]
94
94
95
95
def all (self ):
96
- return [self [alias ] for alias in self ._connections ]
96
+ return [self [alias ] for alias in self .connections_info ]
97
97
98
98
99
99
class ConnectionRouter (object ):
@@ -133,6 +133,7 @@ def __init__(self):
133
133
self .indexes = {}
134
134
self .fields = SortedDict ()
135
135
self ._built = False
136
+ self ._indexes_setup = False
136
137
self .excluded_indexes = getattr (settings , 'HAYSTACK_EXCLUDED_INDEXES' , [])
137
138
self .document_field = getattr (settings , 'HAYSTACK_DOCUMENT_FIELD' , 'text' )
138
139
self ._fieldnames = {}
@@ -250,10 +251,15 @@ def collect_fields(self, index):
250
251
def setup_indexes (self ):
251
252
if not self ._built :
252
253
self .build ()
253
-
254
+
255
+ if self ._indexes_setup :
256
+ return
257
+
254
258
for model_ct , index in self .indexes .items ():
255
259
index ._setup_save ()
256
260
index ._setup_delete ()
261
+
262
+ self ._indexes_setup = True
257
263
258
264
def teardown_indexes (self ):
259
265
if not self ._built :
@@ -262,6 +268,8 @@ def teardown_indexes(self):
262
268
for model_ct , index in self .indexes .items ():
263
269
index ._teardown_save ()
264
270
index ._teardown_delete ()
271
+
272
+ self ._indexes_setup = False
265
273
266
274
def get_indexed_models (self ):
267
275
if not self ._built :
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ def test_discovery(self):
44
44
connections ['default' ]._index = old_ui
45
45
46
46
def test_signal_setup_handling (self ):
47
+ old_ui = connections ['default' ].get_unified_index ()
48
+ connections ['default' ]._index = UnifiedIndex ()
49
+ self .assertEqual (connections ['default' ].get_unified_index ()._indexes_setup , False )
47
50
foo_1 = Foo .objects .create (
48
51
title = 'chekin sigalz' ,
49
52
body = 'stuff'
@@ -56,12 +59,15 @@ def test_signal_setup_handling(self):
56
59
existing_foo = sqs .filter (id = 'discovery.foo.1' )[0 ]
57
60
self .assertEqual (existing_foo .text , u'stuff' )
58
61
62
+ fi .clear ()
59
63
foo_1 = Foo .objects .get (pk = 1 )
60
64
foo_1 .title = 'Checking signals'
61
65
foo_1 .body = 'Stuff.'
62
66
# This save should trigger an update.
63
67
foo_1 .save ()
68
+ self .assertEqual (connections ['default' ].get_unified_index ()._indexes_setup , True )
64
69
65
70
sqs = SearchQuerySet ()
66
71
new_foo = sqs .filter (id = 'discovery.foo.1' )[0 ]
67
72
self .assertEqual (new_foo .text , u'Stuff.' )
73
+ connections ['default' ]._index = old_ui
You can’t perform that action at this time.
0 commit comments