Compare commits

..

No commits in common. "3c40cc381e1413d28149f6f8f3ed35d402406786" and "5b73df899939708029d8adc0c90e0f21f79fa00c" have entirely different histories.

2 changed files with 10 additions and 58 deletions

View File

@ -18,7 +18,7 @@
-include_lib("dudeswave_backend/include/defines.hrl").
-include_lib("storage/include/storage.hrl").
-export([details/2, new/4, update/5, delete/2]).
-export([details/2, new/4, update/5, delete/1]).
-doc """
Return user details.
@ -136,19 +136,17 @@ update(User, Host, Name, Email, Desc) ->
Delete an existing user from the database.
```
-spec delete(User, Host) -> ok | {error, Reason} when
-spec delete(User) -> ok | {error, Reason} when
User :: binary(),
Host :: binary(),
Reason :: term().
```
""".
-spec delete(User, Host) -> ok | {error, Reason} when
-spec delete(User) -> ok | {error, Reason} when
User :: binary(),
Host :: binary(),
Reason :: term().
delete(User, Host) ->
ComplUser = <<User/binary, "@", Host/binary>>,
ok = storage:delete(?USERSBUCK, ComplUser),
ok = storage:delete_set(?COOKIESBUCK, [{user, ComplUser}]).
delete(User) ->
% We are missing the cleanup of the cookies
% here. For that, we need to add at least another
% API to the storage layer.
storage:delete(?USERSBUCK, User).

View File

@ -53,7 +53,7 @@ file:
shrink/2]).
% Public record operation functions
-export([delete/2, delete_set/2, list/2, read/2, write/3, write/4]).
-export([delete/2, list/2, read/2, write/3, write/4]).
% Module callbacks
-export([code_change/3,
@ -462,30 +462,6 @@ Spec:
delete(Bucket, Key) ->
gen_server:call(?MODULE, {delete, Bucket, Key}).
-doc """
Delete a set of records based on the given metadata list.
Spec:
```
-spec delete_set(Bucket, Metadata) -> ok | {error, Reason} when
Bucket :: atom(),
Metadata :: [{Key, Value}],
Key :: term(),
Value :: term(),
Reason :: term().
```
""".
-spec delete_set(Bucket, Metadata) -> ok | {error, Reason} when
Bucket :: atom(),
Metadata :: [{Key, Value}],
Key :: term(),
Value :: term(),
Reason :: term().
delete_set(Bucket, Metadata) ->
gen_server:call(?MODULE, {delete_set, Bucket, Metadata}).
-doc """
Spec:
@ -728,20 +704,6 @@ handle_call({delete, Bucket, Key}, _From, State) ->
{aborted, Reason} -> {reply, {error, Reason}, State}
end;
handle_call({delete_set, Bucket, Metadata}, _From, State) ->
Q = qlc:q([X || X <- mnesia:table(Bucket), filter(Metadata, X#object.metadata)]),
F = fun() ->
Recs = qlc:e(Q),
delete_matching(Bucket, Recs)
end,
case mnesia:transaction(F) of
{atomic, ok} -> {reply, ok, State};
{aborted, Reason} -> {reply, {error, Reason}, State}
end;
handle_call({write, Bucket, Key, Term}, _From, State) ->
handle_call({write, Bucket, Key, Term, []}, _From, State);
@ -829,12 +791,4 @@ filter([H | T], M) ->
Val =:= V -> filter(T, M);
true -> false
end
end.
%
% Delete all the records in a table for every key in the list.
%
delete_matching(_Bucket, []) -> ok;
delete_matching(Bucket, [H | T]) ->
mnesia:delete(Bucket, H#object.key),
delete_matching(Bucket, T).
end.