Extract commit_compacted function
diff --git a/src/couch_index.erl b/src/couch_index.erl
index 2b19cca..25fc62a 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -191,9 +191,7 @@
handle_call({compacted, NewIdxState}, _From, State) ->
#st{
mod=Mod,
- idx_state=OldIdxState,
- updater=Updater,
- commit_delay=Delay
+ idx_state=OldIdxState
} = State,
assert_signature_match(Mod, OldIdxState, NewIdxState),
NewSeq = Mod:get(update_seq, NewIdxState),
@@ -202,26 +200,10 @@
% up to date with the current index. Otherwise indexes could roll back
% (perhaps considerably) to previous points in history.
case NewSeq >= OldSeq of
- true ->
- {ok, NewIdxState1} = Mod:swap_compacted(OldIdxState, NewIdxState),
- % Restart the indexer if it's running.
- case couch_index_updater:is_running(Updater) of
- true -> ok = couch_index_updater:restart(Updater, NewIdxState1);
- false -> ok
- end,
- case State#st.committed of
- true -> erlang:send_after(Delay, self(), commit);
- false -> ok
- end,
- {reply, ok, State#st{
- idx_state=NewIdxState1,
- committed=false
- }};
- _ ->
- {reply, recompact, State}
+ true -> {reply, ok, commit_compacted(NewIdxState, State)};
+ false -> {reply, recompact, State}
end.
-
handle_cast({config_change, NewDelay}, State) ->
MsDelay = 1000 * list_to_integer(NewDelay),
{noreply, State#st{commit_delay=MsDelay}};
@@ -407,3 +389,25 @@
{Sig, Sig} -> ok;
_ -> erlang:error(signature_mismatch)
end.
+
+commit_compacted(NewIdxState, State) ->
+ #st{
+ mod=Mod,
+ idx_state=OldIdxState,
+ updater=Updater,
+ commit_delay=Delay
+ } = State,
+ {ok, NewIdxState1} = Mod:swap_compacted(OldIdxState, NewIdxState),
+ % Restart the indexer if it's running.
+ case couch_index_updater:is_running(Updater) of
+ true -> ok = couch_index_updater:restart(Updater, NewIdxState1);
+ false -> ok
+ end,
+ case State#st.committed of
+ true -> erlang:send_after(Delay, self(), commit);
+ false -> ok
+ end,
+ State#st{
+ idx_state=NewIdxState1,
+ committed=false
+ }.