summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-05-20 10:56:30 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-05-20 10:56:30 +0000
commit4361a832c18be3f9d96e7943f6e1bbce92a94cad (patch)
treebae6550b9bab37854ca70f8595c85e67e74c1f5c
parenta9ce63984c13d126f633a6ab8a243910feac6bc8 (diff)
Replication manager: don't update doc if new state == current state
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
-rw-r--r--src/couchdb/couch_rep.erl19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl
index 5c9fbce6..e4b4264e 100644
--- a/src/couchdb/couch_rep.erl
+++ b/src/couchdb/couch_rep.erl
@@ -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,