Fix recent sort order for retried items (#1829)

* Fix recent sort order for retried items

* Also fix for comments

* don't hide createdAt, order item query inner subquery

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: k00b <k00b@stacker.news>
This commit is contained in:
ekzyis 2025-01-23 00:42:18 +01:00 committed by GitHub
parent ae1942ada7
commit ca7726fda5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 17 additions and 5 deletions

View File

@ -26,7 +26,7 @@ import { verifyHmac } from './wallet'
function commentsOrderByClause (me, models, sort) { function commentsOrderByClause (me, models, sort) {
if (sort === 'recent') { if (sort === 'recent') {
return 'ORDER BY ("Item"."deletedAt" IS NULL) DESC, ("Item".cost > 0 OR "Item"."weightedVotes" - "Item"."weightedDownVotes" > 0) DESC, "Item".created_at DESC, "Item".id DESC' return 'ORDER BY ("Item"."deletedAt" IS NULL) DESC, ("Item".cost > 0 OR "Item"."weightedVotes" - "Item"."weightedDownVotes" > 0) DESC, COALESCE("Item"."invoicePaidAt", "Item".created_at) DESC, "Item".id DESC'
} }
if (me && sort === 'hot') { if (me && sort === 'hot') {
@ -412,10 +412,10 @@ export default {
typeClause(type), typeClause(type),
muteClause(me) muteClause(me)
)} )}
ORDER BY "Item".created_at DESC ORDER BY COALESCE("Item"."invoicePaidAt", "Item".created_at) DESC
OFFSET $2 OFFSET $2
LIMIT $3`, LIMIT $3`,
orderBy: 'ORDER BY "Item"."createdAt" DESC' orderBy: 'ORDER BY COALESCE("Item"."invoicePaidAt", "Item".created_at) DESC'
}, decodedCursor.time, decodedCursor.offset, limit, ...subArr) }, decodedCursor.time, decodedCursor.offset, limit, ...subArr)
break break
case 'top': case 'top':

View File

@ -107,6 +107,7 @@ export default gql`
id: ID! id: ID!
createdAt: Date! createdAt: Date!
updatedAt: Date! updatedAt: Date!
invoicePaidAt: Date
deletedAt: Date deletedAt: Date
deleteScheduledAt: Date deleteScheduledAt: Date
reminderScheduledAt: Date reminderScheduledAt: Date

View File

@ -135,8 +135,8 @@ export default function ItemInfo ({
{embellishUser} {embellishUser}
</Link>} </Link>}
<span> </span> <span> </span>
<Link href={`/items/${item.id}`} title={item.createdAt} className='text-reset' suppressHydrationWarning> <Link href={`/items/${item.id}`} title={item.invoicePaidAt || item.createdAt} className='text-reset' suppressHydrationWarning>
{timeSince(new Date(item.createdAt))} {timeSince(new Date(item.invoicePaidAt || item.createdAt))}
</Link> </Link>
{item.prior && {item.prior &&
<> <>
@ -250,6 +250,11 @@ function InfoDropdownItem ({ item }) {
<div>{item.id}</div> <div>{item.id}</div>
<div>created at</div> <div>created at</div>
<div>{item.createdAt}</div> <div>{item.createdAt}</div>
{item.invoicePaidAt &&
<>
<div>paid at</div>
<div>{item.invoicePaidAt}</div>
</>}
<div>cost</div> <div>cost</div>
<div>{item.cost}</div> <div>{item.cost}</div>
<div>stacked</div> <div>stacked</div>

View File

@ -18,6 +18,7 @@ export const COMMENT_FIELDS = gql`
position position
parentId parentId
createdAt createdAt
invoicePaidAt
deletedAt deletedAt
text text
user { user {

View File

@ -18,6 +18,7 @@ export const ITEM_FIELDS = gql`
id id
parentId parentId
createdAt createdAt
invoicePaidAt
deletedAt deletedAt
title title
url url

View File

@ -0,0 +1,3 @@
-- CreateIndex
CREATE INDEX "Item_invoicePaidAt_idx" ON "Item"("invoicePaidAt");
CREATE INDEX "Item_paid_created_idx" ON "Item" (COALESCE("invoicePaidAt", created_at) DESC);

View File

@ -598,6 +598,7 @@ model Item {
@@index([cost]) @@index([cost])
@@index([url]) @@index([url])
@@index([boost]) @@index([boost])
@@index([invoicePaidAt])
} }
// we use this to denormalize a user's aggregated interactions (zaps) with an item // we use this to denormalize a user's aggregated interactions (zaps) with an item