couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [1/2] couchdb-global-changes git commit: Introduce `global_changes_plugin:transform_change/3`
Date Wed, 12 Aug 2015 16:03:22 GMT
Repository: couchdb-global-changes
Updated Branches:
  refs/heads/master 64ff86c60 -> 00d9c5a1c


Introduce `global_changes_plugin:transform_change/3`


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

Branch: refs/heads/master
Commit: b2b1169af694944be5bd2072e9d7abece0521797
Parents: ccf500c
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Fri Jul 31 06:48:56 2015 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Fri Jul 31 06:48:56 2015 -0700

----------------------------------------------------------------------
 src/global_changes_httpd.erl  | 10 +++++++---
 src/global_changes_plugin.erl | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-global-changes/blob/b2b1169a/src/global_changes_httpd.erl
----------------------------------------------------------------------
diff --git a/src/global_changes_httpd.erl b/src/global_changes_httpd.erl
index dc7c08a..e76b494 100644
--- a/src/global_changes_httpd.erl
+++ b/src/global_changes_httpd.erl
@@ -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 ->

http://git-wip-us.apache.org/repos/asf/couchdb-global-changes/blob/b2b1169a/src/global_changes_plugin.erl
----------------------------------------------------------------------
diff --git a/src/global_changes_plugin.erl b/src/global_changes_plugin.erl
new file mode 100644
index 0000000..d73a541
--- /dev/null
+++ b/src/global_changes_plugin.erl
@@ -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.


Mime
View raw message