Skip to content

Commit

Permalink
use keyset for ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Sep 13, 2023
1 parent 58016e1 commit ace87e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getActorLikes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sql } from 'kysely'
import { InvalidRequestError } from '@atproto/xrpc-server'
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/feed/getActorLikes'
Expand Down Expand Up @@ -70,10 +71,12 @@ const skeleton = async (
let feedItemsQb = feedService
.selectFeedItemQb()
.innerJoin('like', 'like.subject', 'feed_item.uri')
.select(
sql`coalesce("like"."indexedAt", "feed_item"."sortAt")`.as('sortAt'),
)
.where('like.creator', '=', actorDid)
.orderBy('like.indexedAt', 'desc')

const keyset = new FeedKeyset(ref('feed_item.sortAt'), ref('feed_item.cid'))
const keyset = new FeedKeyset(ref('like.sortAt'), ref('feed_item.cid'))

feedItemsQb = paginate(feedItemsQb, {
limit,
Expand Down
10 changes: 5 additions & 5 deletions packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sql } from 'kysely'
import { InvalidRequestError } from '@atproto/xrpc-server'
import { Server } from '../../../../../lexicon'
import { FeedKeyset } from '../util/feed'
Expand Down Expand Up @@ -54,8 +55,10 @@ export default function (server: Server, ctx: AppContext) {
let feedItemsQb = feedService
.selectFeedItemQb()
.innerJoin('like', 'like.subject', 'feed_item.uri')
.select(
sql`coalesce("like"."indexedAt", "feed_item"."sortAt")`.as('sortAt'),
)
.where('like.creator', '=', actorDid)
.orderBy('like.indexedAt', 'desc')

// for access-based auth, enforce blocks
if (requester) {
Expand All @@ -64,10 +67,7 @@ export default function (server: Server, ctx: AppContext) {
)
}

const keyset = new FeedKeyset(
ref('feed_item.sortAt'),
ref('feed_item.cid'),
)
const keyset = new FeedKeyset(ref('like.sortAt'), ref('feed_item.cid'))

feedItemsQb = paginate(feedItemsQb, {
limit,
Expand Down

0 comments on commit ace87e1

Please sign in to comment.