From 0bad010da24aed9d5b6aa3985e19ac5fa3fdbab0 Mon Sep 17 00:00:00 2001 From: Mayya Sharipova Date: Mon, 15 Aug 2016 09:37:05 -0400 Subject: [PATCH] Update to use new purge API COUCHDB-3326 --- src/couch_index_updater.erl | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/couch_index_updater.erl b/src/couch_index_updater.erl index bf31460..053482f 100644 --- a/src/couch_index_updater.erl +++ b/src/couch_index_updater.erl @@ -133,10 +133,7 @@ update(Idx, Mod, IdxState) -> DbUpdateSeq = couch_db:get_update_seq(Db), DbCommittedSeq = couch_db:get_committed_update_seq(Db), - PurgedIdxState = case purge_index(Db, Mod, IdxState) of - {ok, IdxState0} -> IdxState0; - reset -> exit({reset, self()}) - end, + {ok, PurgedIdxState} = purge_index(Db, Mod, IdxState), NumChanges = couch_db:count_changes_since(Db, CurrSeq), @@ -201,11 +198,20 @@ purge_index(Db, Mod, IdxState) -> {ok, DbPurgeSeq} = couch_db:get_purge_seq(Db), IdxPurgeSeq = Mod:get(purge_seq, IdxState), if - DbPurgeSeq == IdxPurgeSeq -> + IdxPurgeSeq == DbPurgeSeq -> {ok, IdxState}; - DbPurgeSeq == IdxPurgeSeq + 1 -> - {ok, PurgedIdRevs} = couch_db:get_last_purged(Db), - Mod:purge(Db, DbPurgeSeq, PurgedIdRevs, IdxState); true -> - reset + FoldFun = fun({PurgeSeq, _UUId, Id, Revs}, Acc) -> + {ok, StateAcc} = Mod:purge(Db, PurgeSeq, [{Id, Revs}], Acc), + StateAcc + end, + {ok, NewStateAcc} = couch_db:fold_purged_docs( + Db, + IdxPurgeSeq, + FoldFun, + IdxState, + [] + ), + Mod:update_local_purge_doc(Db, NewStateAcc), + {ok, NewStateAcc} end.