couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject [3/3] git commit: Add ddoc_updated event
Date Tue, 15 Nov 2011 13:02:31 GMT
Add ddoc_updated event

This is part of the fix for COUCHDB-1309.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/db99d4e0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/db99d4e0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/db99d4e0

Branch: refs/heads/1.2.x
Commit: db99d4e09385d3befa0361b22afe90509b054af8
Parents: 233f4bb
Author: Filipe David Borba Manana <fdmanana@apache.org>
Authored: Sun Nov 13 17:10:10 2011 +0000
Committer: Filipe David Borba Manana <fdmanana@apache.org>
Committed: Tue Nov 15 13:01:24 2011 +0000

----------------------------------------------------------------------
 src/couchdb/couch_db_updater.erl |   40 +++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/db99d4e0/src/couchdb/couch_db_updater.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index b24fc56..87971b3 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -234,13 +234,16 @@ handle_info({update_docs, Client, GroupedDocs, NonRepDocs, MergeConflicts,
     NonRepDocs2 = [{Client, NRDoc} || NRDoc <- NonRepDocs],
     try update_docs_int(Db, GroupedDocs3, NonRepDocs2, MergeConflicts,
                 FullCommit2) of
-    {ok, Db2} ->
+    {ok, Db2, UpdatedDDocIds} ->
         ok = gen_server:call(Db#db.main_pid, {db_updated, Db2}),
         if Db2#db.update_seq /= Db#db.update_seq ->
             couch_db_update_notifier:notify({updated, Db2#db.name});
         true -> ok
         end,
         [catch(ClientPid ! {done, self()}) || ClientPid <- Clients],
+        lists:foreach(fun(DDocId) ->
+            couch_db_update_notifier:notify({ddoc_updated, {Db#db.name, DDocId}})
+        end, UpdatedDDocIds),
         {noreply, Db2}
     catch
         throw: retry ->
@@ -641,14 +644,21 @@ merge_rev_trees(Limit, MergeConflicts, [NewDocs|RestDocsList],
 
 
 
-new_index_entries([], AccById, AccBySeq) ->
-    {AccById, AccBySeq};
-new_index_entries([FullDocInfo|RestInfos], AccById, AccBySeq) ->
-    #doc_info{revs=[#rev_info{deleted=Deleted}|_]} = DocInfo =
+new_index_entries([], AccById, AccBySeq, AccDDocIds) ->
+    {AccById, AccBySeq, AccDDocIds};
+new_index_entries([FullDocInfo|RestInfos], AccById, AccBySeq, AccDDocIds) ->
+    #doc_info{revs=[#rev_info{deleted=Deleted}|_], id=Id} = DocInfo =
             couch_doc:to_doc_info(FullDocInfo),
+    AccDDocIds2 = case Id of
+    <<?DESIGN_DOC_PREFIX, _/binary>> ->
+        [Id | AccDDocIds];
+    _ ->
+        AccDDocIds
+    end,
     new_index_entries(RestInfos,
         [FullDocInfo#full_doc_info{deleted=Deleted}|AccById],
-        [DocInfo|AccBySeq]).
+        [DocInfo|AccBySeq],
+        AccDDocIds2).
 
 
 stem_full_doc_infos(#db{revs_limit=Limit}, DocInfos) ->
@@ -684,8 +694,8 @@ update_docs_int(Db, DocsList, NonRepDocs, MergeConflicts, FullCommit)
->
     % the trees, the attachments are already written to disk)
     {ok, FlushedFullDocInfos} = flush_trees(Db2, NewFullDocInfos, []),
 
-    {IndexFullDocInfos, IndexDocInfos} =
-            new_index_entries(FlushedFullDocInfos, [], []),
+    {IndexFullDocInfos, IndexDocInfos, UpdatedDDocIds} =
+            new_index_entries(FlushedFullDocInfos, [], [], []),
 
     % and the indexes
     {ok, DocInfoByIdBTree2} = couch_btree:add_remove(DocInfoByIdBTree, IndexFullDocInfos,
[]),
@@ -698,16 +708,14 @@ update_docs_int(Db, DocsList, NonRepDocs, MergeConflicts, FullCommit)
->
 
     % Check if we just updated any design documents, and update the validation
     % funs if we did.
-    case lists:any(
-        fun(<<"_design/", _/binary>>) -> true; (_) -> false end, Ids) of
-    false ->
-        Db4 = Db3;
-    true ->
-        Db4 = refresh_validate_doc_funs(Db3)
+    Db4 = case UpdatedDDocIds of
+    [] ->
+        Db3;
+    _ ->
+        refresh_validate_doc_funs(Db3)
     end,
 
-    {ok, commit_data(Db4, not FullCommit)}.
-
+    {ok, commit_data(Db4, not FullCommit), UpdatedDDocIds}.
 
 update_local_docs(Db, []) ->
     {ok, Db};


Mime
View raw message