[Enhancement] Improve ordering of models (#164)

* [WIP] ordering app queries

* Refactored media queries to be self-contained
This commit is contained in:
Kieran
2024-04-03 17:26:46 -07:00
committed by GitHub
parent 4b12764f45
commit e55bcaddd0
10 changed files with 160 additions and 136 deletions
@@ -4,17 +4,21 @@ defmodule PinchflatWeb.Sources.SourceController do
import Ecto.Query, warn: false
alias Pinchflat.Repo
alias Pinchflat.Media
alias Pinchflat.Tasks
alias Pinchflat.Sources
alias Pinchflat.Profiles
alias Pinchflat.MediaQuery
alias Pinchflat.Sources.Source
alias Pinchflat.Media.MediaQuery
alias Pinchflat.Profiles.MediaProfile
alias Pinchflat.Downloading.DownloadingHelpers
alias Pinchflat.SlowIndexing.SlowIndexingHelpers
def index(conn, _params) do
sources = Repo.preload(Sources.list_sources(), :media_profile)
sources =
Source
|> order_by(asc: :custom_name)
|> Repo.all()
|> Repo.preload(:media_profile)
render(conn, :index, sources: sources)
end
@@ -56,8 +60,21 @@ defmodule PinchflatWeb.Sources.SourceController do
|> Tasks.list_tasks_for(nil, [:executing, :available, :scheduled, :retryable])
|> Repo.preload(:job)
pending_media = Media.list_pending_media_items_for(source, limit: 100)
downloaded_media = Media.list_downloaded_media_items_for(source, limit: 100)
pending_media =
MediaQuery.new()
|> MediaQuery.for_source(source)
|> MediaQuery.with_media_pending_download()
|> order_by(desc: :id)
|> limit(100)
|> Repo.all()
downloaded_media =
MediaQuery.new()
|> MediaQuery.for_source(source)
|> MediaQuery.with_media_filepath()
|> order_by(desc: :id)
|> limit(100)
|> Repo.all()
render(conn, :show,
source: source,
@@ -129,7 +146,9 @@ defmodule PinchflatWeb.Sources.SourceController do
end
defp media_profiles do
Profiles.list_media_profiles()
MediaProfile
|> order_by(asc: :name)
|> Repo.all()
end
defp total_downloaded_for(source) do