Skip to content

Commit

Permalink
Replication manager: don't update doc if new state == current state
Browse files Browse the repository at this point in the history
This is to avoid unncessary updates.

This is a backport of revision 1125317 (trunk).


git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1125320 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
fdmanana committed May 20, 2011
1 parent a9ce639 commit 4361a83
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/couchdb/couch_rep.erl
Original file line number Diff line number Diff line change
Expand Up @@ -883,13 +883,18 @@ update_rep_doc({Props} = _RepDoc, KVs) ->

update_rep_doc(RepDb, #doc{body = {RepDocBody}} = RepDoc, KVs) ->
NewRepDocBody = lists:foldl(
fun({<<"_replication_state">> = K, _V} = KV, Body) ->
Body1 = lists:keystore(K, 1, Body, KV),
{Mega, Secs, _} = erlang:now(),
UnixTime = Mega * 1000000 + Secs,
lists:keystore(
<<"_replication_state_time">>, 1,
Body1, {<<"_replication_state_time">>, UnixTime});
fun({<<"_replication_state">> = K, State} = KV, Body) ->
case couch_util:get_value(K, Body) of
State ->
Body;
_ ->
Body1 = lists:keystore(K, 1, Body, KV),
{Mega, Secs, _} = erlang:now(),
UnixTime = Mega * 1000000 + Secs,
lists:keystore(
<<"_replication_state_time">>, 1,
Body1, {<<"_replication_state_time">>, UnixTime})
end;
({K, _V} = KV, Body) ->
lists:keystore(K, 1, Body, KV)
end,
Expand Down

0 comments on commit 4361a83

Please sign in to comment.