Fix query for items with less than 11 parents (#346)

Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
ekzyis 2023-07-07 03:17:12 +02:00 committed by GitHub
parent e0d89a289b
commit 46014d0de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -34,8 +34,8 @@ const createUserFilter = (tag) => {
const createItemUrl = async ({ id }) => {
const [rootItem] = await models.$queryRaw(
'SELECT subpath(path, $1, 1)::text AS id FROM "Item" WHERE id = $2',
-(COMMENT_DEPTH_LIMIT + 1), Number(id)
'SELECT subpath(path, -LEAST(nlevel(path), $1), 1)::text AS id FROM "Item" WHERE id = $2',
COMMENT_DEPTH_LIMIT + 1, Number(id)
)
return `/items/${rootItem.id}` + (rootItem.id !== id ? `?commentId=${id}` : '')
}