-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add quote count to post_agg, add getPostQuotes rework schema rework schema add getPostQuotes to api use posts use posts codegen use items instead of quotes codegen add getPostQuotes add quoteCount to response update lexicon for postview increment post ags add quote to post aggs add quote interface oops add quote table migration * update * bufgen * update params * update to use v2 * logs * rm comment * pass cursor * add index * Update packages/bsky/src/data-plane/server/db/migrations/20240723T220703655Z-quotes.ts Co-authored-by: devin ivy <devinivy@gmail.com> * only if its a post * tests * Discard changes to packages/bsky/tests/views/posts.test.ts * fix client call * Include new quotes agg in test expectation * Use new API for headers * Update packages/bsky/src/data-plane/server/indexing/plugins/post.ts Co-authored-by: devin ivy <devinivy@gmail.com> * revert rm * rm timeout * cursor test * Changeset * Remove pds specific bump --------- Co-authored-by: devin ivy <devinivy@gmail.com> Co-authored-by: Eric Bailey <git@esb.lol>
- Loading branch information
1 parent
922b2e8
commit 2a0c088
Showing
54 changed files
with
1,817 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@atproto/bsky": patch | ||
"@atproto/api": patch | ||
--- | ||
|
||
Adds `app.bsky.feed.getQuotes` lexicon and handlers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "app.bsky.feed.getQuotes", | ||
"defs": { | ||
"main": { | ||
"type": "query", | ||
"description": "Get a list of quotes for a given post.", | ||
"parameters": { | ||
"type": "params", | ||
"required": ["uri"], | ||
"properties": { | ||
"uri": { | ||
"type": "string", | ||
"format": "at-uri", | ||
"description": "Reference (AT-URI) of post record" | ||
}, | ||
"cid": { | ||
"type": "string", | ||
"format": "cid", | ||
"description": "If supplied, filters to quotes of specific version (by CID) of the post record." | ||
}, | ||
"limit": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"maximum": 100, | ||
"default": 50 | ||
}, | ||
"cursor": { "type": "string" } | ||
} | ||
}, | ||
"output": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["uri", "posts"], | ||
"properties": { | ||
"uri": { "type": "string", "format": "at-uri" }, | ||
"cid": { "type": "string", "format": "cid" }, | ||
"cursor": { "type": "string" }, | ||
"posts": { | ||
"type": "array", | ||
"items": { | ||
"type": "ref", | ||
"ref": "app.bsky.feed.defs#postView" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import { Headers, XRPCError } from '@atproto/xrpc' | ||
import { ValidationResult, BlobRef } from '@atproto/lexicon' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { lexicons } from '../../../../lexicons' | ||
import { CID } from 'multiformats/cid' | ||
import * as AppBskyFeedDefs from './defs' | ||
|
||
export interface QueryParams { | ||
/** Reference (AT-URI) of post record */ | ||
uri: string | ||
/** If supplied, filters to quotes of specific version (by CID) of the post record. */ | ||
cid?: string | ||
limit?: number | ||
cursor?: string | ||
} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface OutputSchema { | ||
uri: string | ||
cid?: string | ||
cursor?: string | ||
posts: AppBskyFeedDefs.PostView[] | ||
[k: string]: unknown | ||
} | ||
|
||
export interface CallOptions { | ||
headers?: Headers | ||
} | ||
|
||
export interface Response { | ||
success: boolean | ||
headers: Headers | ||
data: OutputSchema | ||
} | ||
|
||
export function toKnownErr(e: any) { | ||
if (e instanceof XRPCError) { | ||
} | ||
return e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Server } from '../../../../lexicon' | ||
import AppContext from '../../../../context' | ||
import { createPipeline } from '../../../../pipeline' | ||
import { clearlyBadCursor, resHeaders } from '../../../util' | ||
import { | ||
HydrateCtx, | ||
HydrationState, | ||
Hydrator, | ||
} from '../../../../hydration/hydrator' | ||
import { Views } from '../../../../views' | ||
import { mapDefined } from '@atproto/common' | ||
import { QueryParams } from '../../../../lexicon/types/app/bsky/feed/getQuotes' | ||
import { ItemRef, parseString } from '../../../../hydration/util' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
const getQuotes = createPipeline(skeleton, hydration, noBlocks, presentation) | ||
server.app.bsky.feed.getQuotes({ | ||
auth: ctx.authVerifier.standardOptional, | ||
handler: async ({ params, auth, req }) => { | ||
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth) | ||
const labelers = ctx.reqLabelers(req) | ||
const hydrateCtx = await ctx.hydrator.createContext({ | ||
labelers, | ||
viewer, | ||
includeTakedowns, | ||
}) | ||
const result = await getQuotes({ ...params, hydrateCtx }, ctx) | ||
return { | ||
encoding: 'application/json', | ||
body: result, | ||
headers: resHeaders({ labelers: hydrateCtx.labelers }), | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
const skeleton = async (inputs: { | ||
ctx: Context | ||
params: Params | ||
}): Promise<Skeleton> => { | ||
const { ctx, params } = inputs | ||
if (clearlyBadCursor(params.cursor)) { | ||
return { refs: [] } | ||
} | ||
const quotesRes = await ctx.hydrator.dataplane.getQuotesBySubject({ | ||
subject: { uri: params.uri, cid: params.cid }, | ||
cursor: params.cursor, | ||
limit: params.limit, | ||
}) | ||
return { | ||
refs: quotesRes.refs, | ||
cursor: parseString(quotesRes.cursor), | ||
} | ||
} | ||
|
||
const hydration = async (inputs: { | ||
ctx: Context | ||
params: Params | ||
skeleton: Skeleton | ||
}) => { | ||
const { ctx, params, skeleton } = inputs | ||
return await ctx.hydrator.hydratePosts(skeleton.refs, params.hydrateCtx) | ||
} | ||
|
||
const noBlocks = (inputs: { | ||
ctx: Context | ||
skeleton: Skeleton | ||
hydration: HydrationState | ||
}) => { | ||
const { ctx, skeleton, hydration } = inputs | ||
skeleton.refs = skeleton.refs.filter((ref) => { | ||
return !ctx.views.viewerBlockExists(ref.uri, hydration) | ||
}) | ||
return skeleton | ||
} | ||
|
||
const presentation = (inputs: { | ||
ctx: Context | ||
params: Params | ||
skeleton: Skeleton | ||
hydration: HydrationState | ||
}) => { | ||
const { ctx, params, skeleton, hydration } = inputs | ||
const postViews = mapDefined(skeleton.refs, (ref) => { | ||
return ctx.views.post(ref.uri, hydration) | ||
}) | ||
return { | ||
posts: postViews, | ||
cursor: skeleton.cursor, | ||
uri: params.uri, | ||
cid: params.cid, | ||
} | ||
} | ||
|
||
type Context = { | ||
hydrator: Hydrator | ||
views: Views | ||
} | ||
|
||
type Params = QueryParams & { hydrateCtx: HydrateCtx } | ||
|
||
type Skeleton = { | ||
refs: ItemRef[] | ||
cursor?: string | ||
} |
Oops, something went wrong.