Skip to content

Commit

Permalink
Update riakc, move to tiny_pq
Browse files Browse the repository at this point in the history
  • Loading branch information
evanmiller committed Sep 5, 2012
1 parent 4767a79 commit 22cbbd2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 42 deletions.
3 changes: 2 additions & 1 deletion rebar.config
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
{mongodb, ".*", {git, "git://github.com/mongodb/mongodb-erlang.git", {tag, "e5e20a0cbd"}}}, {mongodb, ".*", {git, "git://github.com/mongodb/mongodb-erlang.git", {tag, "e5e20a0cbd"}}},
{mysql, ".*", {git, "git://github.com/dizzyd/erlang-mysql-driver.git", {tag, "16cae84b5e"}}}, {mysql, ".*", {git, "git://github.com/dizzyd/erlang-mysql-driver.git", {tag, "16cae84b5e"}}},
{poolboy, ".*", {git, "git://github.com/devinus/poolboy.git", {tag, "855802e0cc"}}}, {poolboy, ".*", {git, "git://github.com/devinus/poolboy.git", {tag, "855802e0cc"}}},
{riakc, ".*", {git, "git://github.com/basho/riak-erlang-client", {tag, "01a2d3770a"}}} {riakc, ".*", {git, "git://github.com/basho/riak-erlang-client", {tag, "1.3.0"}}},
{tiny_pq, ".*", {git, "git://github.com/evanmiller/tiny_pq", {tag, "HEAD"}}}
]}. ]}.
8 changes: 4 additions & 4 deletions src/boss_news_controller.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ handle_call({set_watch, WatchId, TopicString, CallBack, UserInfo, TTL}, From, St
user_info = UserInfo, user_info = UserInfo,
exp_time = ExpTime, exp_time = ExpTime,
ttl = TTL}, NewState#state.watch_dict), ttl = TTL}, NewState#state.watch_dict),
ttl_tree = boss_pq:insert_value(ExpTime, WatchId, NewState#state.ttl_tree) ttl_tree = tiny_pq:insert_value(ExpTime, WatchId, NewState#state.ttl_tree)
}}; }};
Error -> {reply, Error, State} Error -> {reply, Error, State}
end; end;
handle_call({cancel_watch, WatchId}, _From, State) -> handle_call({cancel_watch, WatchId}, _From, State) ->
{RetVal, NewState} = case dict:find(WatchId, State#state.watch_dict) of {RetVal, NewState} = case dict:find(WatchId, State#state.watch_dict) of
{ok, #watch{ exp_time = ExpTime }} -> {ok, #watch{ exp_time = ExpTime }} ->
NewTree = boss_pq:move_value(ExpTime, 0, WatchId, State#state.ttl_tree), NewTree = tiny_pq:move_value(ExpTime, 0, WatchId, State#state.ttl_tree),
{ok, State#state{ ttl_tree = NewTree }}; {ok, State#state{ ttl_tree = NewTree }};
_ -> _ ->
{{error, not_found}, State} {{error, not_found}, State}
Expand All @@ -124,7 +124,7 @@ handle_call({extend_watch, WatchId}, _From, State0) ->
{RetVal, NewState} = case dict:find(WatchId, State#state.watch_dict) of {RetVal, NewState} = case dict:find(WatchId, State#state.watch_dict) of
{ok, #watch{ exp_time = ExpTime, ttl = TTL } = Watch} -> {ok, #watch{ exp_time = ExpTime, ttl = TTL } = Watch} ->
NewExpTime = future_time(TTL), NewExpTime = future_time(TTL),
NewTree = boss_pq:move_value(ExpTime, NewExpTime, WatchId, State#state.ttl_tree), NewTree = tiny_pq:move_value(ExpTime, NewExpTime, WatchId, State#state.ttl_tree),
{ok, State#state{ ttl_tree = NewTree, {ok, State#state{ ttl_tree = NewTree,
watch_dict = dict:store(WatchId, Watch#watch{ exp_time = NewExpTime }, State#state.watch_dict) }}; watch_dict = dict:store(WatchId, Watch#watch{ exp_time = NewExpTime }, State#state.watch_dict) }};
_ -> _ ->
Expand Down Expand Up @@ -252,7 +252,7 @@ activate_record(Id, Attrs) ->


prune_expired_entries(#state{ ttl_tree = Tree } = State) -> prune_expired_entries(#state{ ttl_tree = Tree } = State) ->
Now = future_time(0), Now = future_time(0),
{NewState, NewTree} = boss_pq:prune(fun(WatchId, StateAcc) -> {NewState, NewTree} = tiny_pq:prune_collect_old(fun(WatchId, StateAcc) ->
#watch{ watch_list = WatchList } = dict:fetch(WatchId, StateAcc#state.watch_dict), #watch{ watch_list = WatchList } = dict:fetch(WatchId, StateAcc#state.watch_dict),
NewState = lists:foldr(fun NewState = lists:foldr(fun
({id, TopicString}, Acc) -> ({id, TopicString}, Acc) ->
Expand Down
37 changes: 0 additions & 37 deletions src/boss_pq.erl

This file was deleted.

0 comments on commit 22cbbd2

Please sign in to comment.