fix(library): library-neighbors JSONB cast 오류 — EXISTS 서브쿼리로 교체
This commit is contained in:
@@ -559,14 +559,21 @@ async def get_library_neighbors(
|
||||
if not path:
|
||||
return LibraryNeighborsResponse(prev=None, next=None, path=None)
|
||||
|
||||
# 같은 path (정확히) 의 자료들 — title 오름차순
|
||||
# 같은 path (정확히) 의 자료들 — title 오름차순.
|
||||
# user_tags 는 JSONB. 다른 endpoint 와 일관되게 EXISTS + jsonb_array_elements_text 사용.
|
||||
from sqlalchemy import text as sql_text
|
||||
exact_tag = f"{LIBRARY_PREFIX}{path}"
|
||||
res = await session.execute(
|
||||
select(Document.id, Document.title)
|
||||
.where(
|
||||
Document.deleted_at == None, # noqa: E711
|
||||
Document.category == "library",
|
||||
Document.user_tags.op("@>")(f'["{exact_tag}"]'),
|
||||
sql_text("""
|
||||
EXISTS (
|
||||
SELECT 1 FROM jsonb_array_elements_text(documents.user_tags) AS t
|
||||
WHERE t = :exact
|
||||
)
|
||||
""").bindparams(exact=exact_tag),
|
||||
)
|
||||
.order_by(Document.title.asc().nullslast(), Document.id.asc())
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user