Skip to content

Commit

Permalink
Appview: control max thread depth (#3015)
Browse files Browse the repository at this point in the history
* appview: timeout getFollowsFollowing, fail open

* build

* reduce thread size

* setup thread depth configs

* tidy
  • Loading branch information
devinivy authored Nov 19, 2024
1 parent 0f7f536 commit 64d9310
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-and-push-bsky-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- main
- divy/timeout-polo
env:
REGISTRY: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_REGISTRY }}
USERNAME: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_USERNAME }}
Expand Down
14 changes: 12 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { HydrateCtx, Hydrator } from '../../../../hydration/hydrator'
import { Views } from '../../../../views'
import { DataPlaneClient, isDataplaneError, Code } from '../../../../data-plane'
import { postUriToThreadgateUri } from '../../../../util/uris'
import { ServerConfig } from '../../../../config'

export default function (server: Server, ctx: AppContext) {
const getPostThread = createPipeline(
Expand Down Expand Up @@ -75,7 +76,7 @@ const skeleton = async (inputs: SkeletonFnInput<Context, Params>) => {
const res = await ctx.dataplane.getThread({
postUri: anchor,
above: params.parentHeight,
below: params.depth,
below: getDepth(ctx, anchor, params),
})
return {
anchor,
Expand Down Expand Up @@ -109,7 +110,7 @@ const presentation = (
const { ctx, params, skeleton, hydration } = inputs
const thread = ctx.views.thread(skeleton, hydration, {
height: params.parentHeight,
depth: params.depth,
depth: getDepth(ctx, skeleton.anchor, params),
})
if (isNotFoundPost(thread)) {
// @TODO technically this could be returned as a NotFoundPost based on lexicon
Expand All @@ -132,6 +133,7 @@ type Context = {
dataplane: DataPlaneClient
hydrator: Hydrator
views: Views
cfg: ServerConfig
}

type Params = QueryParams & { hydrateCtx: HydrateCtx }
Expand All @@ -140,3 +142,11 @@ type Skeleton = {
anchor: string
uris: string[]
}

const getDepth = (ctx: Context, anchor: string, params: Params) => {
let maxDepth = ctx.cfg.maxThreadDepth
if (ctx.cfg.bigThreadUris.has(anchor) && ctx.cfg.bigThreadDepth) {
maxDepth = ctx.cfg.bigThreadDepth
}
return maxDepth ? Math.min(maxDepth, params.depth) : params.depth
}
26 changes: 26 additions & 0 deletions packages/bsky/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export interface ServerConfigValues {
blobCacheLocation?: string
statsigKey?: string
statsigEnv?: string
// threads
bigThreadUris: Set<string>
bigThreadDepth?: number
maxThreadDepth?: number
// client config
clientCheckEmailConfirmed?: boolean
}
Expand Down Expand Up @@ -133,6 +137,13 @@ export class ServerConfig {
!indexedAtEpoch || !isNaN(indexedAtEpoch.getTime()),
'invalid BSKY_INDEXED_AT_EPOCH',
)
const bigThreadUris = new Set(envList(process.env.BSKY_BIG_THREAD_URIS))
const bigThreadDepth = process.env.BSKY_BIG_THREAD_DEPTH
? parseInt(process.env.BSKY_BIG_THREAD_DEPTH || '', 10)
: undefined
const maxThreadDepth = process.env.BSKY_MAX_THREAD_DEPTH
? parseInt(process.env.BSKY_MAX_THREAD_DEPTH || '', 10)
: undefined
return new ServerConfig({
version,
debugMode,
Expand Down Expand Up @@ -170,6 +181,9 @@ export class ServerConfig {
statsigEnv,
clientCheckEmailConfirmed,
indexedAtEpoch,
bigThreadUris,
bigThreadDepth,
maxThreadDepth,
...stripUndefineds(overrides ?? {}),
})
}
Expand Down Expand Up @@ -330,6 +344,18 @@ export class ServerConfig {
get indexedAtEpoch() {
return this.cfg.indexedAtEpoch
}

get bigThreadUris() {
return this.cfg.bigThreadUris
}

get bigThreadDepth() {
return this.cfg.bigThreadDepth
}

get maxThreadDepth() {
return this.cfg.maxThreadDepth
}
}

function stripUndefineds(
Expand Down
1 change: 1 addition & 0 deletions packages/dev-env/src/bsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class TestBsky {
bsyncHttpVersion: '1.1',
modServiceDid: cfg.modServiceDid ?? 'did:example:invalidMod',
labelsFromIssuerDids: [EXAMPLE_LABELER],
bigThreadUris: new Set(),
...cfg,
adminPasswords: [ADMIN_PASSWORD],
})
Expand Down

0 comments on commit 64d9310

Please sign in to comment.