Skip to content

Commit

Permalink
make requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Th3-M4jor committed May 19, 2024
1 parent cc4e450 commit 2d838d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
16 changes: 8 additions & 8 deletions lib/nostrum/cache/message_cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Nostrum.Cache.MessageCache do
# callbacks

@doc """
Retrieve a single `Nostrum.Struct.Message` from the cache by channel id and message id.
Retrieve a single `Nostrum.Struct.Message` from the cache by its ID.
"""
@callback get(Message.id()) :: {:ok, Message.t()} | {:error, :not_found}

Expand Down Expand Up @@ -68,19 +68,19 @@ defmodule Nostrum.Cache.MessageCache do
@callback delete(Channel.id(), Message.id()) :: Message.t() | nil

@doc """
Deletes multiple messages from the cache, any message id's given
Deletes multiple messages from the cache, any message IDs given
will always be for the same channel.
Returns a list of the deleted messages,
if a message was not found in the cache, it will
still be included in the returned list with
only the id and channel_id set.
Returns a list of the deleted messages.
Note that if a message was not found in the cache, it will
not be included in the returned list.
"""
@callback bulk_delete(Channel.id(), [Message.id()]) :: [Message.t()]

@doc """
Callback for when a channel is deleted
any messages in the cache for that channel should be removed.
Called when a channel is deleted.
Any messages in the cache for the channel should be removed.
"""
@callback channel_delete(Channel.id()) :: :ok

Expand Down
6 changes: 1 addition & 5 deletions lib/nostrum/cache/message_cache/mnesia.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ if Code.ensure_loaded?(:mnesia) do
@moduledoc """
An Mnesia-based cache for messages.
Please note that this module is only compiled if Mnesia is available on
your system. See the Mnesia section of the [State](functionality/state.md)
documentation for more information.
To retrieve the table name used by this cache, use `table/0`.
#{Nostrum.Cache.Base.mnesia_note()}
By default, the cache will store up to 10,000 messages.
To change this limit, add the `:message_cache_size_limit` key to the `:caches`
Expand Down
4 changes: 2 additions & 2 deletions src/nostrum_message_cache_qlc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ by_channel(RequestedChannelId, Cache) ->
ChannelId =:= RequestedChannelId]),
qlc:keysort(1, Q1).

% lookup the ids of all cached messages for a given channel.
% lookup the IDs of all cached messages for a given channel.
-spec all_message_ids_in_channel('Elixir.Nostrum.Struct.Channel':id(), module()) -> qlc:query_handle().
all_message_ids_in_channel(RequestedChannelId, ?MNESIA_CACHE) ->
qlc:q([MessageId || {_Tag, MessageId, ChannelId, _, _Message} <- ?MNESIA_CACHE:query_handle(),
Expand Down Expand Up @@ -103,7 +103,7 @@ sorted_by_age_with_limit(Cache, Limit) ->

sort_with_limit(Q1, Limit) ->
Fn = fun (MessageId, {Count1, Set1, Largest1}) ->
if (MessageId < Largest1) and (Count1 >= Limit) ->
if (MessageId < Largest1) andalso (Count1 >= Limit) ->
Set2 = gb_sets:delete(Largest1, Set1),
Set3 = gb_sets:insert(MessageId, Set2),
Largest2 = gb_sets:largest(Set3),
Expand Down

0 comments on commit 2d838d6

Please # to comment.