Permalink
Browse files

Handle ddoc_updated event correctly.

COUCHDB-1309 introduced a new update event of the form {ddoc_updated,
{DbName, DDocId}}. Unfortunately it did not update
couch_db_update_notifier with a clause that can marshal this to JSON
successfully, breaking all uses of [update_notification]

This commit improves event encoding so that the above renders as
{"type":"ddoc_updated","db":"DbName","id":"DDocId"}

COUCHDB-1508
  • Loading branch information...
1 parent f0d6f19 commit 0e9c5a5afbb35f6fdaa059fa56c6d5ccb87baec9 @rnewson rnewson committed Jul 4, 2012
Showing with 11 additions and 2 deletions.
  1. +11 −2 src/couchdb/couch_db_update_notifier.erl
@@ -53,8 +53,8 @@ handle_event(Event, Fun) when is_function(Fun, 1) ->
handle_event(Event, {Fun, FunAcc}) ->
FunAcc2 = Fun(Event, FunAcc),
{ok, {Fun, FunAcc2}};
-handle_event({EventAtom, DbName}, Pid) ->
- Obj = {[{type, list_to_binary(atom_to_list(EventAtom))}, {db, DbName}]},
+handle_event({EventType, EventDesc}, Pid) ->
+ Obj = encode_event(EventType, EventDesc),
ok = couch_os_process:send(Pid, Obj),
{ok, Pid}.
@@ -71,3 +71,12 @@ handle_info({'EXIT', _, _}, Pid) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+
+encode_event(EventType, EventDesc) when is_atom(EventType) ->
+ encode_event(atom_to_list(EventType), EventDesc);
+encode_event(EventType, EventDesc) when is_list(EventType) ->
+ encode_event(?l2b(EventType), EventDesc);
+encode_event(EventType, {DbName, DocId}) ->
+ {[{type, EventType}, {db, DbName}, {id, DocId}]};
+encode_event(EventType, DbName) ->
+ {[{type, EventType}, {db, DbName}]}.

0 comments on commit 0e9c5a5

Please sign in to comment.