Skip to content

Commit

Permalink
use the returnbody option of riak_client:put/5 instead of riak_object…
Browse files Browse the repository at this point in the history
…:apply_updates/1
  • Loading branch information
beerriot committed Jul 8, 2010
1 parent 0057dc8 commit 17a5780
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
4 changes: 3 additions & 1 deletion include/luwak.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
-define(BLOCK_DEFAULT, 1000000).
-define(HASH_LEN, 512).

-define(TIMEOUT_DEFAULT, 60000).

-record(split, {head=[], midhead=[], middle=[], midtail=[], tail=[]}).

-ifndef(EUNIT_HRL).
Expand All @@ -18,4 +20,4 @@
-define(debugFmt(S, As), ok).
-endif.

-endif.
-endif.
2 changes: 1 addition & 1 deletion src/luwak_block.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ create(Riak, Data) ->
{type, block}
],
Obj = riak_object:new(?N_BUCKET, skerl:hexhash(?HASH_LEN, Data), Value),
{Riak:put(Obj,2), Obj}.
Riak:put(Obj, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]).

data(Val) when is_list(Val) ->
proplists:get_value(data, Val);
Expand Down
19 changes: 7 additions & 12 deletions src/luwak_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ create(Riak, Name, Properties, Attributes) when is_binary(Name) ->
{root, undefined}
],
Obj = riak_object:new(?O_BUCKET, Name, Value),
ok = Riak:put(Obj, 2),
{ok, Obj}.
Riak:put(Obj, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]).

%% @spec set_attributes(Riak :: riak(), Obj :: luwak_file(),
%% Attributes :: dict())
Expand All @@ -67,9 +66,8 @@ create(Riak, Name, Properties, Attributes) when is_binary(Name) ->
set_attributes(Riak, Obj, Attributes) ->
Value = lists:keyreplace(attributes, 1, riak_object:get_value(Obj),
{attributes, Attributes}),
Obj2 = riak_object:apply_updates(riak_object:update_value(Obj, Value)),
ok = Riak:put(Obj2, 2),
{ok, Obj2}.
Obj2 = riak_object:update_value(Obj, Value),
Riak:put(Obj2, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]).

%% @spec get_attributes(Obj :: luwak_file()) -> dict()
%% @doc Gets the attribute dictionary from the file handle.
Expand Down Expand Up @@ -140,9 +138,8 @@ update_root(Riak, Obj, NewRoot) ->
ObjVal2 = lists:keyreplace(ancestors, 1, ObjVal1,
{ancestors, [OldRoot|Ancestors]}),
ObjVal3 = lists:keyreplace(root, 1, ObjVal2, {root, NewRoot}),
Obj2 = riak_object:apply_updates(riak_object:update_value(Obj, ObjVal3)),
ok = Riak:put(Obj2, 2),
{ok, Obj2}.
Obj2 = riak_object:update_value(Obj, ObjVal3),
Riak:put(Obj2, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]).

%% @private
update_checksum(Riak, Obj, ChecksumFun) ->
Expand All @@ -151,10 +148,8 @@ update_checksum(Riak, Obj, ChecksumFun) ->
ObjVal1 = riak_object:get_value(Obj),
ObjVal2 = lists:keyreplace(checksum, 1, ObjVal1,
{checksum, {sha1, ChecksumFun()}}),
Obj2 = riak_object:apply_updates(riak_object:update_value(Obj,
ObjVal2)),
ok = Riak:put(Obj2, 2),
{ok, Obj2};
Obj2 = riak_object:update_value(Obj, ObjVal2),
Riak:put(Obj2, 2, 2, ?TIMEOUT_DEFAULT, [{retunbody, true}]);
_ ->
{ok, Obj}
end.
Expand Down
2 changes: 1 addition & 1 deletion src/luwak_tree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ create_node(Riak, Children) ->
N = #n{created=now(),children=Children},
Name = skerl:hexhash(?HASH_LEN, term_to_binary(Children)),
Obj = riak_object:new(?N_BUCKET, Name, N),
{Riak:put(Obj, 2), Obj}.
Riak:put(Obj, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]).

truncate(List) when is_list(List) ->
lists:map(fun({Data,Length}) -> {truncate(Data),Length} end, List);
Expand Down

0 comments on commit 17a5780

Please sign in to comment.