feat: Use MapSet to track file changes

This commit is contained in:
Daniel Kempkens 2023-08-14 20:01:46 +02:00
parent ede1d3cb2e
commit b84b5daca1
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
2 changed files with 8 additions and 12 deletions

View file

@ -123,10 +123,6 @@
packages.default = beamPackages.mixRelease { packages.default = beamPackages.mixRelease {
inherit pname version; inherit pname version;
buildInputs = [ ] ++ lib.optionals isLinux (with pkgs; [
inotify-tools
]);
src = gitignoreSource ./.; src = gitignoreSource ./.;
mixNixDeps = import ./mix.nix { inherit pkgs lib beamPackages; }; mixNixDeps = import ./mix.nix { inherit pkgs lib beamPackages; };
}; };

View file

@ -10,8 +10,8 @@ defmodule BdfrBrowser.Importer do
typedstruct do typedstruct do
field :fs_pid, pid field :fs_pid, pid
field :post_changes, [Path.t()], default: [] field :post_changes, [Path.t()], default: MapSet.new()
field :chat_changes, [Path.t()], default: [] field :chat_changes, [Path.t()], default: MapSet.new()
end end
end end
@ -109,11 +109,11 @@ defmodule BdfrBrowser.Importer do
end end
@impl true @impl true
def handle_cast(:background_import_changes, state) do def handle_cast(:background_import_changes, %State{post_changes: post_changes, chat_changes: chat_changes} = state) do
_ = subreddits() _ = subreddits()
_ = changed_posts_and_comments(state.post_changes) _ = post_changes |> MapSet.to_list() |> changed_posts_and_comments()
_ = changed_chats(state.chat_changes) _ = chat_changes |> MapSet.to_list() |> changed_chats()
{:noreply, %State{state | post_changes: [], chat_changes: []}} {:noreply, %State{state | post_changes: MapSet.new(), chat_changes: MapSet.new()}}
end end
@impl true @impl true
@ -126,10 +126,10 @@ defmodule BdfrBrowser.Importer do
new_state = new_state =
cond do cond do
String.contains?(path, chat_directory) and ext == ".json" -> String.contains?(path, chat_directory) and ext == ".json" ->
%State{state | chat_changes: [path | state.chat_changes]} %State{state | chat_changes: MapSet.put(state.chat_changes, path)}
String.contains?(path, base_directory) and ext == ".json" -> String.contains?(path, base_directory) and ext == ".json" ->
%State{state | post_changes: [path | state.post_changes]} %State{state | post_changes: MapSet.put(state.post_changes, path)}
true -> true ->
state state