Skip to content

Commit e2840ec

Browse files
committed
Changed Post.score to be an int to fix pagination sorting
1 parent c10da80 commit e2840ec

4 files changed

Lines changed: 10 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,7 @@ authorization: Bearker <access_token>
169169

170170
```gql
171171
query {
172-
rankedFeed: postCollection(
173-
orderBy: [
174-
{ voteRank: AscNullsFirst }
175-
{ score: DescNullsFirst }
176-
{ createdAt: DescNullsFirst }
177-
]
178-
) {
172+
rankedFeed: postCollection(orderBy: [{ voteRank: AscNullsFirst }]) {
179173
edges {
180174
post: node {
181175
id

app/pages/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import { usePaginatedQuery } from "../lib/use-paginated-query";
1313
const IndexRouteQuery = gql(/* GraphQL */ `
1414
query IndexRouteQuery($profileId: UUID!, $after: Cursor) {
1515
feed: postCollection(
16-
orderBy: [
17-
{ voteRank: AscNullsFirst }
18-
{ score: DescNullsFirst }
19-
{ createdAt: DescNullsFirst }
20-
]
16+
orderBy: [{ voteRank: AscNullsFirst }]
2117
first: 15
2218
after: $after
2319
) {

data/supabase/06-update-post-vote-counts.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ SELECT
1616
ELSE
1717
0
1818
END), 0) "voteDelta",
19-
sum(
19+
round(coalesce(sum(
2020
CASE WHEN direction = 'UP' THEN
2121
1
2222
WHEN direction = 'DOWN' THEN
2323
- 1
2424
ELSE
2525
0
26-
END) - 1 / (DATE_PART('hour', now() - max("Vote"."createdAt")) + 2) ^ 1.8 AS "score",
27-
rank() OVER (ORDER BY coalesce(sum( CASE WHEN direction = 'UP' THEN
26+
END) - 1 / (DATE_PART('hour', now() - max("Vote"."createdAt")) + 2) ^ 1.8 * 100000, -2147483648)::numeric, 0) AS "score",
27+
rank() OVER (ORDER BY round(coalesce(sum( CASE WHEN direction = 'UP' THEN
2828
1
2929
WHEN direction = 'DOWN' THEN
3030
- 1
3131
ELSE
3232
0
33-
END) - 1 / (DATE_PART('hour', now() - max("Vote"."createdAt")) + 2) ^ 1.8, '-infinity')
33+
END) - 1 / (DATE_PART('hour', now() - max("Vote"."createdAt")) + 2) ^ 1.8 * 100000, -2147483648)::numeric, 0)
3434
DESC,
3535
"Post"."createdAt" DESC,
3636
"Post".title ASC) "voteRank"

graphql/schema/schema.graphql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ type Post {
324324
downVoteTotal: Int!
325325
voteTotal: Int!
326326
voteRank: Int!
327-
score: Float
327+
score: Int
328328
voteDelta: Int!
329329
commentCollection(
330330
"""Query the first `n` records in the collection"""
@@ -399,7 +399,7 @@ input PostFilter {
399399
downVoteTotal: IntFilter
400400
voteTotal: IntFilter
401401
voteRank: IntFilter
402-
score: FloatFilter
402+
score: IntFilter
403403
voteDelta: IntFilter
404404
}
405405

@@ -413,7 +413,7 @@ input PostInsertInput {
413413
downVoteTotal: Int
414414
voteTotal: Int
415415
voteRank: Int
416-
score: Float
416+
score: Int
417417
voteDelta: Int
418418
}
419419

@@ -450,7 +450,7 @@ input PostUpdateInput {
450450
downVoteTotal: Int
451451
voteTotal: Int
452452
voteRank: Int
453-
score: Float
453+
score: Int
454454
voteDelta: Int
455455
}
456456

0 commit comments

Comments
 (0)