Commits

Anonymous committed b0787f3

get deleted event

  • Participants
  • Parent commits fb759a9
  • Branches dbchanges

Comments (0)

Files changed (1)

src/couchdb/couch_httpd_misc_handlers.erl

 % waits for a db_updated msg, if there are multiple msgs, collects them.
 wait_db_changes(Timeout, TimeoutFun) ->
     receive {db_change, Change, DbName} -> 
-        {updated, Change, DbName}
+        get_rest_db_changes(Change, DbName)
     after Timeout ->
         case TimeoutFun() of
         ok -> wait_db_changes(Timeout, TimeoutFun);
         end
     end.
 
+get_rest_db_changes(Change, DbName) ->
+    receive {db_change, Change1, DbName1} -> get_rest_db_changes(Change1, DbName1)
+    after 0 -> {updated, Change, DbName}
+    end.
+
 get_rest_db_changes() ->
     receive {db_change, _, _} -> get_rest_db_changes()
     after 0 -> updated
 keep_sending_dbs_changes(#httpd{user_ctx=UserCtx}=Req, Resp, ChangeInc, Prepend, Timeout, TimeoutFun, ResponseType) ->
     case wait_db_changes(Timeout, TimeoutFun) of
         {updated, Change, DbName} ->
-            {ChangeInc2, Prepend2} = case couch_db:open(DbName, [{user_ctx, UserCtx}]) of
-                {ok, Db} ->
-                    {ok, Info} = couch_db:get_db_info(Db),
-                    Seq = proplists:get_value(update_seq, Info),
-                    send_change(Resp, Prepend, Change, DbName, Seq),
+            {ChangeInc2, Prepend2} = case Change of
+                deleted ->
+                    send_change(Resp, Prepend, Change, DbName, 0),
                     Inc = ChangeInc + 1,
                     {Inc, <<"\n">>};
-                _ -> 
-                    {ChangeInc, Prepend}
-            end,
+                _ ->
+                    case couch_db:open(DbName, [{user_ctx, UserCtx}]) of
+                        {ok, Db} ->
+                            {ok, Info} = couch_db:get_db_info(Db),
+                            Seq = proplists:get_value(update_seq, Info),
+                            couch_db:close(Db),
+                            send_change(Resp, Prepend, Change, DbName, Seq),
+                            Inc = ChangeInc + 1,
+                            {Inc, <<"\n">>};
+                        _ -> 
+                            {ChangeInc, Prepend}
+                    end
+                end,
             if
                 ChangeInc2 > 0, ResponseType =:= "longpoll" ->
                     couch_httpd:end_json_response(Resp);