Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Introduce global_changes_plugin:transform_change/3
  • Loading branch information
iilyak committed Jul 31, 2015
1 parent ccf500c commit b2b1169af694944be5bd2072e9d7abece0521797
Showing 2 changed files with 47 additions and 3 deletions.
@@ -13,6 +13,7 @@
-module(global_changes_httpd).

-export([handle_global_changes_req/1]).
-export([default_transform_change/2]).

-include_lib("couch/include/couch_db.hrl").

@@ -65,8 +66,11 @@ handle_global_changes_req(#httpd{method='GET'}=Req) ->
handle_global_changes_req(Req) ->
chttpd:send_method_not_allowed(Req, "GET").

transform_change(Username, Change) ->
global_changes_plugin:transform_change(Username, Change,
fun default_transform_change/2).

transform_change(Username, _Resp, {Props}) ->
default_transform_change(Username, {Props}) ->
{id, Id} = lists:keyfind(id, 1, Props),
{seq, Seq} = lists:keyfind(seq, 1, Props),
Info = case binary:split(Id, <<":">>) of
@@ -100,7 +104,7 @@ changes_callback(start, #acc{feed="continuous"}=Acc) ->
{ok, Acc#acc{resp=Resp, last_data_sent_time=os:timestamp()}};
changes_callback({change, Change0}, #acc{feed="continuous"}=Acc) ->
#acc{resp=Resp, username=Username} = Acc,
case transform_change(Username, Resp, Change0) of
case transform_change(Username, Change0) of
skip ->
{ok, maybe_send_heartbeat(Acc)};
Change ->
@@ -140,7 +144,7 @@ changes_callback(start, Acc) ->
}};
changes_callback({change, Change0}, Acc) ->
#acc{resp=Resp, prepend=Prepend, username=Username} = Acc,
case transform_change(Username, Resp, Change0) of
case transform_change(Username, Change0) of
skip ->
{ok, maybe_send_heartbeat(Acc)};
Change ->
@@ -0,0 +1,40 @@
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.

-module(global_changes_plugin).

-export([transform_change/3]).

-include_lib("couch/include/couch_db.hrl").

-define(SERVICE_ID, global_changes).


%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------

transform_change(Username, Change, Default) ->
maybe_handle(transform_change, [Username, Change], Default).

%% ------------------------------------------------------------------
%% Internal Function Definitions
%% ------------------------------------------------------------------

maybe_handle(Func, Args, Default) ->
Handle = couch_epi:get_handle(?SERVICE_ID),
case couch_epi:apply(Handle, ?SERVICE_ID, Func, Args, [ignore_providers]) of
[] ->
apply(Default, Args);
[Result] ->
Result
end.

0 comments on commit b2b1169

Please sign in to comment.