From ace87e1e76f119f2bcacef7f01e3b0bf0a4ddd22 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 13 Sep 2023 13:37:01 -0500 Subject: [PATCH] use keyset for ordering --- packages/bsky/src/api/app/bsky/feed/getActorLikes.ts | 7 +++++-- .../src/app-view/api/app/bsky/feed/getActorLikes.ts | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/bsky/src/api/app/bsky/feed/getActorLikes.ts b/packages/bsky/src/api/app/bsky/feed/getActorLikes.ts index 0a1106ca7bf..49d2d512e58 100644 --- a/packages/bsky/src/api/app/bsky/feed/getActorLikes.ts +++ b/packages/bsky/src/api/app/bsky/feed/getActorLikes.ts @@ -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' @@ -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, diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts b/packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts index c5cf7df93ce..4a7d8c7028c 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts @@ -1,3 +1,4 @@ +import { sql } from 'kysely' import { InvalidRequestError } from '@atproto/xrpc-server' import { Server } from '../../../../../lexicon' import { FeedKeyset } from '../util/feed' @@ -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) { @@ -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,