You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2011/05/20 12:56:30 UTC

svn commit: r1125320 - /couchdb/branches/1.1.x/src/couchdb/couch_rep.erl

Author: fdmanana
Date: Fri May 20 10:56:30 2011
New Revision: 1125320

URL: http://svn.apache.org/viewvc?rev=1125320&view=rev
Log:
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).

Modified:
    couchdb/branches/1.1.x/src/couchdb/couch_rep.erl

Modified: couchdb/branches/1.1.x/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_rep.erl?rev=1125320&r1=1125319&r2=1125320&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_rep.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_rep.erl Fri May 20 10:56:30 2011
@@ -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,