Skip to content

Commit

Permalink
Updated fast indexing to respect title filters (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
kieraneglin authored Mar 27, 2024
1 parent 8513dee commit ba0ded0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pinchflat/media/media.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ defmodule Pinchflat.Media do
|> where([mi], mi.id == ^media_item.id and is_nil(mi.media_filepath))
|> where(^build_format_clauses(media_item.source.media_profile))
|> where(^maybe_apply_cutoff_date(media_item.source))
|> where(^maybe_apply_title_regex(media_item.source))
|> Repo.exists?()
end

Expand Down
21 changes: 21 additions & 0 deletions test/pinchflat/media_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,27 @@ defmodule Pinchflat.MediaTest do

assert Media.pending_download?(media_item)
end

test "returns true if the content matches the title regex" do
source = source_fixture(%{title_filter_regex: "(?i)^FOO$"})
media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "foo"})

assert Media.pending_download?(media_item)
end

test "returns false if the content doesn't match the title regex" do
source = source_fixture(%{title_filter_regex: "(?i)^FOO$"})
media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "bar"})

refute Media.pending_download?(media_item)
end

test "return true if there is no title regex" do
source = source_fixture(%{title_filter_regex: nil})
media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "foo"})

assert Media.pending_download?(media_item)
end
end

describe "search/1" do
Expand Down

0 comments on commit ba0ded0

Please sign in to comment.