Refactors

This commit is contained in:
Kieran Eglin 2025-01-02 15:16:29 -08:00
parent 3c15884bf3
commit 9590fd1a98
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 26 additions and 8 deletions

View file

@ -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

View file

@ -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, "")

View file

@ -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