Bumped RSS feed limit; fixed ordering (#241)
This commit is contained in:
@@ -24,11 +24,12 @@ defmodule Pinchflat.Podcasts.PodcastHelpers do
|
|||||||
Returns: [%MediaItem{}]
|
Returns: [%MediaItem{}]
|
||||||
"""
|
"""
|
||||||
def persisted_media_items_for(source, opts \\ []) do
|
def persisted_media_items_for(source, opts \\ []) do
|
||||||
limit = Keyword.get(opts, :limit, 500)
|
limit = Keyword.get(opts, :limit, 1_000)
|
||||||
|
|
||||||
MediaQuery.new()
|
MediaQuery.new()
|
||||||
|> MediaQuery.for_source(source)
|
|> MediaQuery.for_source(source)
|
||||||
|> MediaQuery.with_media_filepath()
|
|> MediaQuery.with_media_filepath()
|
||||||
|
|> order_by(desc: :upload_date)
|
||||||
|> Repo.maybe_limit(limit)
|
|> Repo.maybe_limit(limit)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.filter(fn media_item -> File.exists?(media_item.media_filepath) end)
|
|> Enum.filter(fn media_item -> File.exists?(media_item.media_filepath) end)
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
|
|||||||
Only MediaItems that have been persisted will be included in the feed.
|
Only MediaItems that have been persisted will be included in the feed.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
- `:limit` - The maximum number of media items to include in the feed. Defaults to 300.
|
- `:limit` - The maximum number of media items to include in the feed. Defaults to 2,000.
|
||||||
|
|
||||||
Returns an XML document as a string.
|
Returns an XML document as a string.
|
||||||
"""
|
"""
|
||||||
def build(source, opts \\ []) do
|
def build(source, opts \\ []) do
|
||||||
limit = Keyword.get(opts, :limit, 300)
|
limit = Keyword.get(opts, :limit, 2_000)
|
||||||
url_base = Keyword.get(opts, :url_base, PinchflatWeb.Endpoint.url())
|
url_base = Keyword.get(opts, :url_base, PinchflatWeb.Endpoint.url())
|
||||||
|
|
||||||
media_items = PodcastHelpers.persisted_media_items_for(source, limit: limit)
|
media_items = PodcastHelpers.persisted_media_items_for(source, limit: limit)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ defmodule PinchflatWeb.Podcasts.PodcastController do
|
|||||||
def rss_feed(conn, %{"uuid" => uuid}) do
|
def rss_feed(conn, %{"uuid" => uuid}) do
|
||||||
source = Repo.get_by!(Source, uuid: uuid)
|
source = Repo.get_by!(Source, uuid: uuid)
|
||||||
url_base = url(conn, ~p"/")
|
url_base = url(conn, ~p"/")
|
||||||
xml = RssFeedBuilder.build(source, limit: 300, url_base: url_base)
|
xml = RssFeedBuilder.build(source, limit: 2_000, url_base: url_base)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/rss+xml")
|
|> put_resp_content_type("application/rss+xml")
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
defmodule Pinchflat.Repo.Migrations.AddDateIndexesToMediaItems do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create(index(:media_items, [:media_downloaded_at]))
|
||||||
|
create(index(:media_items, [:media_redownloaded_at]))
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -22,6 +22,16 @@ defmodule Pinchflat.Podcasts.PodcastHelpersTest do
|
|||||||
|
|
||||||
assert [] = PodcastHelpers.persisted_media_items_for(source, limit: 0)
|
assert [] = PodcastHelpers.persisted_media_items_for(source, limit: 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "orders by upload date where newest is first" do
|
||||||
|
source = source_fixture()
|
||||||
|
|
||||||
|
oldest = media_item_with_attachments(%{source_id: source.id, upload_date: now_minus(2, :day)})
|
||||||
|
current = media_item_with_attachments(%{source_id: source.id, upload_date: now()})
|
||||||
|
older = media_item_with_attachments(%{source_id: source.id, upload_date: now_minus(1, :days)})
|
||||||
|
|
||||||
|
assert [^current, ^older, ^oldest] = PodcastHelpers.persisted_media_items_for(source)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "select_cover_image/2" do
|
describe "select_cover_image/2" do
|
||||||
|
|||||||
Reference in New Issue
Block a user