Skip to content

Commit ca7726f

Browse files
ekzyishuumn
andauthored
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 <[email protected]> Co-authored-by: k00b <[email protected]>
1 parent ae1942a commit ca7726f

File tree

7 files changed

+17
-5
lines changed

7 files changed

+17
-5
lines changed

api/resolvers/item.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { verifyHmac } from './wallet'
2626

2727
function commentsOrderByClause (me, models, sort) {
2828
if (sort === 'recent') {
29-
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'
29+
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'
3030
}
3131

3232
if (me && sort === 'hot') {
@@ -412,10 +412,10 @@ export default {
412412
typeClause(type),
413413
muteClause(me)
414414
)}
415-
ORDER BY "Item".created_at DESC
415+
ORDER BY COALESCE("Item"."invoicePaidAt", "Item".created_at) DESC
416416
OFFSET $2
417417
LIMIT $3`,
418-
orderBy: 'ORDER BY "Item"."createdAt" DESC'
418+
orderBy: 'ORDER BY COALESCE("Item"."invoicePaidAt", "Item".created_at) DESC'
419419
}, decodedCursor.time, decodedCursor.offset, limit, ...subArr)
420420
break
421421
case 'top':

api/typeDefs/item.js

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export default gql`
107107
id: ID!
108108
createdAt: Date!
109109
updatedAt: Date!
110+
invoicePaidAt: Date
110111
deletedAt: Date
111112
deleteScheduledAt: Date
112113
reminderScheduledAt: Date

components/item-info.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ export default function ItemInfo ({
135135
{embellishUser}
136136
</Link>}
137137
<span> </span>
138-
<Link href={`/items/${item.id}`} title={item.createdAt} className='text-reset' suppressHydrationWarning>
139-
{timeSince(new Date(item.createdAt))}
138+
<Link href={`/items/${item.id}`} title={item.invoicePaidAt || item.createdAt} className='text-reset' suppressHydrationWarning>
139+
{timeSince(new Date(item.invoicePaidAt || item.createdAt))}
140140
</Link>
141141
{item.prior &&
142142
<>
@@ -250,6 +250,11 @@ function InfoDropdownItem ({ item }) {
250250
<div>{item.id}</div>
251251
<div>created at</div>
252252
<div>{item.createdAt}</div>
253+
{item.invoicePaidAt &&
254+
<>
255+
<div>paid at</div>
256+
<div>{item.invoicePaidAt}</div>
257+
</>}
253258
<div>cost</div>
254259
<div>{item.cost}</div>
255260
<div>stacked</div>

fragments/comments.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const COMMENT_FIELDS = gql`
1818
position
1919
parentId
2020
createdAt
21+
invoicePaidAt
2122
deletedAt
2223
text
2324
user {

fragments/items.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const ITEM_FIELDS = gql`
1818
id
1919
parentId
2020
createdAt
21+
invoicePaidAt
2122
deletedAt
2223
title
2324
url
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- CreateIndex
2+
CREATE INDEX "Item_invoicePaidAt_idx" ON "Item"("invoicePaidAt");
3+
CREATE INDEX "Item_paid_created_idx" ON "Item" (COALESCE("invoicePaidAt", created_at) DESC);

prisma/schema.prisma

+1
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ model Item {
598598
@@index([cost])
599599
@@index([url])
600600
@@index([boost])
601+
@@index([invoicePaidAt])
601602
}
602603

603604
// we use this to denormalize a user's aggregated interactions (zaps) with an item

0 commit comments

Comments
 (0)