Appview: handle out-of-date cursor with feed.getLikes (#2474)
* appview: temporarily revert move to GetLikesBySubjectSorted * appview: provide error when using old cursor value on getLikes
This commit is contained in:
parent
499fabe7b6
commit
7cdcd5848c
packages/bsky/src
@ -13,6 +13,7 @@ import { Views } from '../../../../views'
|
||||
import { parseString } from '../../../../hydration/util'
|
||||
import { creatorFromUri } from '../../../../views/util'
|
||||
import { clearlyBadCursor, resHeaders } from '../../../util'
|
||||
import { InvalidRequestError } from '@atproto/xrpc-server'
|
||||
|
||||
export default function (server: Server, ctx: AppContext) {
|
||||
const getLikes = createPipeline(skeleton, hydration, noBlocks, presentation)
|
||||
@ -41,6 +42,11 @@ const skeleton = async (inputs: {
|
||||
if (clearlyBadCursor(params.cursor)) {
|
||||
return { likes: [] }
|
||||
}
|
||||
if (looksLikeNonSortedCursor(params.cursor)) {
|
||||
throw new InvalidRequestError(
|
||||
'Cursor appear to be out of date, please try reloading.',
|
||||
)
|
||||
}
|
||||
const likesRes = await ctx.hydrator.dataplane.getLikesBySubjectSorted({
|
||||
subject: { uri: params.uri, cid: params.cid },
|
||||
cursor: params.cursor,
|
||||
@ -116,3 +122,9 @@ type Skeleton = {
|
||||
likes: string[]
|
||||
cursor?: string
|
||||
}
|
||||
|
||||
const looksLikeNonSortedCursor = (cursor: string | undefined) => {
|
||||
// the old cursor values used with getLikesBySubject() were dids.
|
||||
// we now use getLikesBySubjectSorted(), whose cursors look like timestamps.
|
||||
return cursor?.startsWith('did:')
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
import assert from 'node:assert'
|
||||
import { keyBy } from '@atproto/common'
|
||||
import { ServiceImpl } from '@connectrpc/connect'
|
||||
import { Service } from '../../../proto/bsky_connect'
|
||||
import { Database } from '../db'
|
||||
import { TimeCidKeyset, paginate } from '../db/pagination'
|
||||
import { keyBy } from '@atproto/common'
|
||||
|
||||
export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({
|
||||
async getLikesBySubjectSorted(req) {
|
||||
@ -34,8 +35,10 @@ export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({
|
||||
}
|
||||
},
|
||||
|
||||
async getLikesBySubject(_req) {
|
||||
throw new Error('deprecated in favor of getLikesBySubjectSorted')
|
||||
// @NOTE deprecated in favor of getLikesBySubjectSorted
|
||||
async getLikesBySubject(req, context) {
|
||||
assert(this.getLikesBySubjectSorted)
|
||||
return this.getLikesBySubjectSorted(req, context)
|
||||
},
|
||||
|
||||
async getLikesByActorAndSubjects(req) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user