diff --git a/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex b/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex index 48cd2d5..433af5a 100644 --- a/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex +++ b/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex @@ -201,8 +201,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do archive_contents = source |> get_media_items_for_download_archive() - |> Enum.map(fn media_item -> "youtube #{media_item.media_id}" end) - |> Enum.join("\n") + |> Enum.map_join("\n", fn media_item -> "youtube #{media_item.media_id}" end) case File.write(tmpfile, archive_contents) do :ok -> tmpfile diff --git a/lib/pinchflat/utils/filesystem_utils.ex b/lib/pinchflat/utils/filesystem_utils.ex index bac512e..e7acb86 100644 --- a/lib/pinchflat/utils/filesystem_utils.ex +++ b/lib/pinchflat/utils/filesystem_utils.ex @@ -44,10 +44,21 @@ defmodule Pinchflat.Utils.FilesystemUtils do Returns binary() """ - # TODO: consider namespacing these folders like they do in activestorage def generate_metadata_tmpfile(type) do + filename = StringUtils.random_string(64) + # This "namespacing" is more to help with development since things get + # weird in my editor when there are thousands of files in a single directory + first_two = String.slice(filename, 0..1) + second_two = String.slice(filename, 2..3) tmpfile_directory = Application.get_env(:pinchflat, :tmpfile_directory) - filepath = Path.join([tmpfile_directory, "#{StringUtils.random_string(64)}.#{type}"]) + + filepath = + Path.join([ + tmpfile_directory, + first_two, + second_two, + "#{filename}.#{type}" + ]) :ok = write_p!(filepath, "") diff --git a/test/pinchflat/slow_indexing/media_collection_indexing_worker_test.exs b/test/pinchflat/slow_indexing/media_collection_indexing_worker_test.exs index 45b5436..c8b5360 100644 --- a/test/pinchflat/slow_indexing/media_collection_indexing_worker_test.exs +++ b/test/pinchflat/slow_indexing/media_collection_indexing_worker_test.exs @@ -51,13 +51,16 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do describe "perform/1" do setup do stub(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end) + stub(AppriseRunnerMock, :run, fn _, _ -> {:ok, ""} end) :ok end test "indexes the source if it should be indexed" do - expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end) + expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> + {:ok, ""} + end) source = source_fixture(index_frequency_minutes: 10) @@ -65,7 +68,9 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do end test "indexes the source no matter what if the source has never been indexed before" do - expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end) + expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> + {:ok, ""} + end) source = source_fixture(index_frequency_minutes: 0, last_indexed_at: nil) @@ -73,7 +78,9 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do end test "indexes the source no matter what if the 'force' arg is passed" do - expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> {:ok, ""} end) + expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> + {:ok, ""} + end) source = source_fixture(index_frequency_minutes: 0, last_indexed_at: DateTime.utc_now()) @@ -88,7 +95,8 @@ defmodule Pinchflat.SlowIndexing.MediaCollectionIndexingWorkerTest do {:ok, ""} end) - source = source_fixture(collection_type: :channel, index_frequency_minutes: 0, last_indexed_at: DateTime.utc_now()) + source = + source_fixture(collection_type: :channel, index_frequency_minutes: 0, last_indexed_at: DateTime.utc_now()) perform_job(MediaCollectionIndexingWorker, %{id: source.id, force: true}) end