Skip to content

Commit

Permalink
stop duplicating work listings when filtering by has_preview (#801)
Browse files Browse the repository at this point in the history
Fixes: #799
  • Loading branch information
zkat authored Apr 20, 2024
1 parent 74696d0 commit 9acd644
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/banchan/works/works.ex
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,15 @@ defmodule Banchan.Works do
defp filter_has_preview(q, opts) do
if Keyword.get(opts, :has_preview, true) do
q
|> join(:inner, [work: w], upload in assoc(w, :uploads), as: :upload)
|> where([upload: u], not is_nil(u.preview_id))
|> where(
[],
subquery(
from u in WorkUpload,
where: u.work_id == parent_as(:work).id,
where: not is_nil(u.preview_id),
select: count(u.id)
) > 0
)
else
q
end
Expand Down

0 comments on commit 9acd644

Please sign in to comment.