77from share .admin .util import admin_url
88from share .models .index_backfill import IndexBackfill
99from share .search .index_messenger import IndexMessenger
10- from share .search import index_strategy
10+ from share .search .index_strategy import (
11+ IndexStrategy ,
12+ all_strategy_names ,
13+ each_strategy ,
14+ parse_strategy_name ,
15+ parse_specific_index_name ,
16+ )
1117
1218
1319logger = logging .getLogger (__name__ )
@@ -25,19 +31,15 @@ def search_indexes_view(request):
2531 },
2632 )
2733 if request .method == 'POST' :
28- _specific_index = index_strategy . get_specific_index (request .POST ['specific_indexname ' ])
34+ _index_strategy = parse_strategy_name (request .POST ['strategy_name ' ])
2935 _pls_doer = PLS_DOERS [request .POST ['pls_do' ]]
30- _pls_doer (_specific_index )
31- _redirect_id = (
32- _specific_index .index_strategy .name
33- if _pls_doer is _pls_delete
34- else _specific_index .indexname
35- )
36+ _pls_doer (_index_strategy )
37+ _redirect_id = _index_strategy .strategy_name
3638 return HttpResponseRedirect ('#' .join ((request .path , _redirect_id )))
3739
3840
3941def search_index_mappings_view (request , index_name ):
40- _specific_index = index_strategy . get_specific_index (index_name )
42+ _specific_index = parse_specific_index_name (index_name )
4143 _mappings = _specific_index .pls_get_mappings ()
4244 return JsonResponse (_mappings )
4345
@@ -52,30 +54,23 @@ def _mappings_url_prefix():
5254
5355
5456def _index_status_by_strategy ():
55- backfill_by_indexname : dict [str , IndexBackfill ] = {
56- backfill . specific_indexname : backfill
57- for backfill in (
57+ _backfill_by_checksum : dict [str , IndexBackfill ] = {
58+ _backfill . strategy_checksum : _backfill
59+ for _backfill in (
5860 IndexBackfill .objects
59- .filter (index_strategy_name__in = index_strategy . all_index_strategies (). keys ())
61+ .filter (index_strategy_name__in = all_strategy_names ())
6062 )
6163 }
6264 status_by_strategy = {}
6365 _messenger = IndexMessenger ()
64- for _index_strategy in index_strategy .all_index_strategies ().values ():
65- current_index = _index_strategy .for_current_index ()
66- status_by_strategy [_index_strategy .name ] = {
67- 'current' : {
68- 'status' : current_index .pls_get_status (),
69- 'backfill' : _serialize_backfill (
70- current_index ,
71- backfill_by_indexname .get (current_index .indexname ),
72- ),
73- },
74- 'prior' : sorted ((
75- specific_index .pls_get_status ()
76- for specific_index in _index_strategy .each_specific_index ()
77- if not specific_index .is_current
78- ), reverse = True ),
66+ for _index_strategy in each_strategy ():
67+ _current_backfill = (
68+ _backfill_by_checksum .get (str (_index_strategy .CURRENT_STRATEGY_CHECKSUM ))
69+ or _backfill_by_checksum .get (_index_strategy .indexname_prefix ) # backcompat
70+ )
71+ status_by_strategy [_index_strategy .strategy_name ] = {
72+ 'status' : _index_strategy .pls_get_strategy_status (),
73+ 'backfill' : _serialize_backfill (_index_strategy , _current_backfill ),
7974 'queues' : [
8075 {
8176 'name' : _queue_name ,
@@ -91,14 +86,14 @@ def _index_status_by_strategy():
9186
9287
9388def _serialize_backfill (
94- specific_index : index_strategy . IndexStrategy . SpecificIndex ,
89+ strategy : IndexStrategy ,
9590 backfill : IndexBackfill | None ,
9691):
97- if not specific_index .is_current :
92+ if not strategy .is_current :
9893 return {}
9994 if not backfill :
10095 return {
101- 'can_start_backfill' : specific_index .pls_check_exists (),
96+ 'can_start_backfill' : strategy .pls_check_exists (),
10297 }
10398 return {
10499 'backfill_status' : backfill .backfill_status ,
@@ -109,35 +104,35 @@ def _serialize_backfill(
109104 }
110105
111106
112- def _pls_setup (specific_index ):
113- assert specific_index .is_current
114- specific_index .pls_setup ()
107+ def _pls_setup (index_strategy : IndexStrategy ):
108+ assert index_strategy .is_current
109+ index_strategy .pls_setup ()
115110
116111
117- def _pls_start_keeping_live (specific_index ):
118- specific_index .pls_start_keeping_live ()
112+ def _pls_start_keeping_live (index_strategy : IndexStrategy ):
113+ index_strategy .pls_start_keeping_live ()
119114
120115
121- def _pls_stop_keeping_live (specific_index ):
122- specific_index .pls_stop_keeping_live ()
116+ def _pls_stop_keeping_live (index_strategy : IndexStrategy ):
117+ index_strategy .pls_stop_keeping_live ()
123118
124119
125- def _pls_start_backfill (specific_index ):
126- assert specific_index .is_current
127- specific_index . index_strategy .pls_start_backfill ()
120+ def _pls_start_backfill (index_strategy : IndexStrategy ):
121+ assert index_strategy .is_current
122+ index_strategy .pls_start_backfill ()
128123
129124
130- def _pls_mark_backfill_complete (specific_index ):
131- specific_index . index_strategy .pls_mark_backfill_complete ()
125+ def _pls_mark_backfill_complete (index_strategy : IndexStrategy ):
126+ index_strategy .pls_mark_backfill_complete ()
132127
133128
134- def _pls_make_default_for_searching (specific_index ):
135- specific_index . index_strategy .pls_make_default_for_searching (specific_index )
129+ def _pls_make_default_for_searching (index_strategy : IndexStrategy ):
130+ index_strategy .pls_make_default_for_searching ()
136131
137132
138- def _pls_delete (specific_index ):
139- assert not specific_index .is_current
140- specific_index . pls_delete ()
133+ def _pls_delete (index_strategy : IndexStrategy ):
134+ assert not index_strategy .is_current
135+ index_strategy . pls_teardown ()
141136
142137
143138PLS_DOERS = {
0 commit comments