Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Update to use new purge API
Browse files Browse the repository at this point in the history
COUCHDB-3326
  • Loading branch information
Mayya Sharipova authored and jiangphcn committed Mar 29, 2017
1 parent 4e779f2 commit 0bad010
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/couch_index_updater.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down Expand Up @@ -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.

0 comments on commit 0bad010

Please sign in to comment.