Use maps instead of dicts in HTTP upload modules
ejabberd currently depends on Erlang/OTP 17.1 or higher, so we can now use maps.
This commit is contained in:
parent
6ac839dd76
commit
63777f830d
|
@ -108,7 +108,7 @@
|
||||||
get_url :: binary(),
|
get_url :: binary(),
|
||||||
service_url :: binary() | undefined,
|
service_url :: binary() | undefined,
|
||||||
thumbnail :: boolean(),
|
thumbnail :: boolean(),
|
||||||
slots = dict:new() :: term()}). % dict:dict() requires Erlang 17.
|
slots = #{} :: map()}).
|
||||||
|
|
||||||
-record(media_info,
|
-record(media_info,
|
||||||
{type :: binary(),
|
{type :: binary(),
|
||||||
|
@ -676,18 +676,18 @@ create_slot(#state{service_url = ServiceURL},
|
||||||
-spec add_slot(slot(), pos_integer(), timer:tref(), state()) -> state().
|
-spec add_slot(slot(), pos_integer(), timer:tref(), state()) -> state().
|
||||||
|
|
||||||
add_slot(Slot, Size, Timer, #state{slots = Slots} = State) ->
|
add_slot(Slot, Size, Timer, #state{slots = Slots} = State) ->
|
||||||
NewSlots = dict:store(Slot, {Size, Timer}, Slots),
|
NewSlots = maps:put(Slot, {Size, Timer}, Slots),
|
||||||
State#state{slots = NewSlots}.
|
State#state{slots = NewSlots}.
|
||||||
|
|
||||||
-spec get_slot(slot(), state()) -> {ok, {pos_integer(), timer:tref()}} | error.
|
-spec get_slot(slot(), state()) -> {ok, {pos_integer(), timer:tref()}} | error.
|
||||||
|
|
||||||
get_slot(Slot, #state{slots = Slots}) ->
|
get_slot(Slot, #state{slots = Slots}) ->
|
||||||
dict:find(Slot, Slots).
|
maps:find(Slot, Slots).
|
||||||
|
|
||||||
-spec del_slot(slot(), state()) -> state().
|
-spec del_slot(slot(), state()) -> state().
|
||||||
|
|
||||||
del_slot(Slot, #state{slots = Slots} = State) ->
|
del_slot(Slot, #state{slots = Slots} = State) ->
|
||||||
NewSlots = dict:erase(Slot, Slots),
|
NewSlots = maps:remove(Slot, Slots),
|
||||||
State#state{slots = NewSlots}.
|
State#state{slots = NewSlots}.
|
||||||
|
|
||||||
-spec slot_el(slot() | binary(), state() | binary(), binary()) -> xmlel().
|
-spec slot_el(slot() | binary(), state() | binary(), binary()) -> xmlel().
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
access_hard_quota :: atom(),
|
access_hard_quota :: atom(),
|
||||||
max_days :: pos_integer() | infinity,
|
max_days :: pos_integer() | infinity,
|
||||||
docroot :: binary(),
|
docroot :: binary(),
|
||||||
disk_usage = dict:new() :: term(),
|
disk_usage = #{} :: map(),
|
||||||
timers :: [timer:tref()]}).
|
timers :: [timer:tref()]}).
|
||||||
|
|
||||||
-type state() :: #state{}.
|
-type state() :: #state{}.
|
||||||
|
@ -172,7 +172,7 @@ handle_cast({handle_slot_request, #jid{user = U, server = S} = JID, Path, Size},
|
||||||
_ ->
|
_ ->
|
||||||
0
|
0
|
||||||
end,
|
end,
|
||||||
OldSize = case dict:find({U, S}, DiskUsage) of
|
OldSize = case maps:find({U, S}, DiskUsage) of
|
||||||
{ok, Value} ->
|
{ok, Value} ->
|
||||||
Value;
|
Value;
|
||||||
error ->
|
error ->
|
||||||
|
@ -202,7 +202,7 @@ handle_cast({handle_slot_request, #jid{user = U, server = S} = JID, Path, Size},
|
||||||
enforce_quota(Path, Size, OldSize, SoftQuota, HardQuota)
|
enforce_quota(Path, Size, OldSize, SoftQuota, HardQuota)
|
||||||
end,
|
end,
|
||||||
NewDiskUsage = if is_integer(NewSize) ->
|
NewDiskUsage = if is_integer(NewSize) ->
|
||||||
dict:store({U, S}, NewSize, DiskUsage);
|
maps:put({U, S}, NewSize, DiskUsage);
|
||||||
true ->
|
true ->
|
||||||
DiskUsage
|
DiskUsage
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue