diff options
author | Robert Newson <robert.newson@cloudant.com> | 2011-08-12 13:37:46 +0100 |
---|---|---|
committer | Robert Newson <robert.newson@cloudant.com> | 2011-08-12 13:42:02 +0100 |
commit | 52ff89ff7996e839b9e2f91fd76184d362a8aeb0 (patch) | |
tree | 7b084002e2321dc99abf16dc2077e6b9af5343f6 /apps/couch/src | |
parent | 8c9228ae2e4081d4d79fda46ff026a18e79a9232 (diff) |
Allow asynchronous view group updates.
Diffstat (limited to 'apps/couch/src')
-rw-r--r-- | apps/couch/src/couch_view_group.erl | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/apps/couch/src/couch_view_group.erl b/apps/couch/src/couch_view_group.erl index de64ef51..9aa6cd8d 100644 --- a/apps/couch/src/couch_view_group.erl +++ b/apps/couch/src/couch_view_group.erl @@ -14,7 +14,7 @@ -behaviour(gen_server). %% API --export([start_link/1, request_group/2, request_group_info/1]). +-export([start_link/1, request_group/2, trigger_group_update/2, request_group_info/1]). -export([open_db_group/2, open_temp_group/5, design_doc_to_view_group/1,design_root/2]). %% gen_server callbacks @@ -54,6 +54,9 @@ request_group_info(Pid) -> throw(Error) end. +trigger_group_update(Pid, RequestSeq) -> + gen_server:cast(Pid, {update_group, RequestSeq}). + % from template start_link(InitArgs) -> case gen_server:start_link(couch_view_group, @@ -153,6 +156,16 @@ handle_call(request_group_info, _From, State) -> GroupInfo = get_group_info(State), {reply, {ok, GroupInfo}, State}. +handle_cast({update_group, RequestSeq}, + #group_state{ + group=#group{current_seq=Seq}=Group, + updater_pid=nil}=State) when RequestSeq > Seq -> + Owner = self(), + Pid = spawn_link(fun()-> couch_view_updater:update(Owner, Group) end), + {noreply, State#group_state{updater_pid=Pid}}; +handle_cast({update_group, _RequestSeq}, State) -> + {noreply, State}; + handle_cast({start_compact, CompactFun}, #group_state{compactor_pid=nil} = State) -> #group_state{ |