Skip to content

Commit

Permalink
deterministic thread orders in dataplane
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Dec 14, 2023
1 parent 764e0da commit cecc669
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 240 deletions.
2 changes: 1 addition & 1 deletion packages/bsky/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const presentation = (
inputs: PresentationFnInput<Context, Params, Skeleton>,
) => {
const { ctx, params, skeleton, hydration } = inputs
const thread = ctx.views.thread(skeleton.anchor, hydration, {
const thread = ctx.views.thread(skeleton, hydration, {
height: params.parentHeight,
depth: params.depth,
})
Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/src/data-plane/server/routes/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({
depth: below,
})
.selectFrom('descendent')
.innerJoin('post', 'post.uri', 'descendent.uri')
.orderBy('post.sortAt', 'desc')
.selectAll()
.execute(),
])
Expand Down
6 changes: 4 additions & 2 deletions packages/bsky/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,18 +502,20 @@ export class Views {
// ------------

thread(
anchor: string,
skele: { anchor: string; uris: string[] },
state: HydrationState,
opts: { height: number; depth: number },
): ThreadViewPost | NotFoundPost | BlockedPost {
const { anchor, uris } = skele
const post = this.post(anchor, state)
if (!post) return this.notFoundPost(anchor)
if (this.viewerBlockExists(post.author.did, state)) {
return this.blockedPost(anchor, post.author.did, state)
}
const includedPosts = new Set<string>([anchor])
const childrenByParentUri: Record<string, string[]> = {}
state.posts?.forEach((post, uri) => {
uris.forEach((uri) => {
const post = state.posts?.get(uri)
const parentUri = post?.record.reply?.parent.uri
if (!parentUri) return
if (includedPosts.has(uri)) return
Expand Down
1 change: 1 addition & 0 deletions packages/bsky/tests/admin/repo-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('admin repo search view', () => {
sc = network.getSeedClient()
await usersBulkSeed(sc)
headers = network.pds.adminAuthHeaders()
await network.processAll()
})

afterAll(async () => {
Expand Down
40 changes: 20 additions & 20 deletions packages/bsky/tests/views/__snapshots__/blocks.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,30 @@ Object {
},
},
"replies": Array [
Object {
"$type": "app.bsky.feed.defs#blockedPost",
"author": Object {
"did": "user(2)",
"viewer": Object {
"blockedBy": false,
"blocking": "record(5)",
},
},
"blocked": true,
"uri": "record(0)",
},
Object {
"$type": "app.bsky.feed.defs#threadViewPost",
"post": Object {
"author": Object {
"avatar": "https://bsky.public.url/img/avatar/plain/user(3)/cids(1)@jpeg",
"did": "user(2)",
"avatar": "https://bsky.public.url/img/avatar/plain/user(4)/cids(1)@jpeg",
"did": "user(3)",
"displayName": "bobby",
"handle": "bob.test",
"labels": Array [],
"viewer": Object {
"blockedBy": false,
"following": "record(6)",
"following": "record(7)",
"muted": false,
},
},
Expand All @@ -278,8 +290,8 @@ Object {
"images": Array [
Object {
"alt": "tests/sample-img/key-landscape-small.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(3)/cids(4)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(3)/cids(4)@jpeg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(4)/cids(4)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(4)/cids(4)@jpeg",
},
],
},
Expand All @@ -290,15 +302,15 @@ Object {
"cts": "1970-01-01T00:00:00.000Z",
"neg": false,
"src": "did:example:labeler",
"uri": "record(5)",
"uri": "record(6)",
"val": "test-label",
},
Object {
"cid": "cids(3)",
"cts": "1970-01-01T00:00:00.000Z",
"neg": false,
"src": "did:example:labeler",
"uri": "record(5)",
"uri": "record(6)",
"val": "test-label-2",
},
],
Expand Down Expand Up @@ -336,22 +348,10 @@ Object {
},
"replyCount": 1,
"repostCount": 0,
"uri": "record(5)",
"uri": "record(6)",
"viewer": Object {},
},
},
Object {
"$type": "app.bsky.feed.defs#blockedPost",
"author": Object {
"did": "user(4)",
"viewer": Object {
"blockedBy": false,
"blocking": "record(7)",
},
},
"blocked": true,
"uri": "record(0)",
},
],
},
}
Expand Down
116 changes: 58 additions & 58 deletions packages/bsky/tests/views/__snapshots__/mute-lists.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,12 @@ Object {
"$type": "app.bsky.feed.defs#threadViewPost",
"post": Object {
"author": Object {
"avatar": "https://bsky.public.url/img/avatar/plain/user(3)/cids(1)@jpeg",
"did": "user(2)",
"displayName": "bobby",
"handle": "bob.test",
"handle": "carol.test",
"labels": Array [],
"viewer": Object {
"blockedBy": false,
"followedBy": "record(8)",
"following": "record(7)",
"muted": true,
"mutedByList": Object {
Expand All @@ -176,55 +175,12 @@ Object {
},
},
"cid": "cids(3)",
"embed": Object {
"$type": "app.bsky.embed.images#view",
"images": Array [
Object {
"alt": "tests/sample-img/key-landscape-small.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(3)/cids(5)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(3)/cids(5)@jpeg",
},
],
},
"indexedAt": "1970-01-01T00:00:00.000Z",
"labels": Array [
Object {
"cid": "cids(3)",
"cts": "1970-01-01T00:00:00.000Z",
"neg": false,
"src": "did:example:labeler",
"uri": "record(5)",
"val": "test-label",
},
Object {
"cid": "cids(3)",
"cts": "1970-01-01T00:00:00.000Z",
"neg": false,
"src": "did:example:labeler",
"uri": "record(5)",
"val": "test-label-2",
},
],
"labels": Array [],
"likeCount": 0,
"record": Object {
"$type": "app.bsky.feed.post",
"createdAt": "1970-01-01T00:00:00.000Z",
"embed": Object {
"$type": "app.bsky.embed.images",
"images": Array [
Object {
"alt": "tests/sample-img/key-landscape-small.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
"ref": Object {
"$link": "cids(5)",
},
"size": 4114,
},
},
],
},
"reply": Object {
"parent": Object {
"cid": "cids(0)",
Expand All @@ -235,9 +191,9 @@ Object {
"uri": "record(0)",
},
},
"text": "hear that label_me label_me_2",
"text": "of course",
},
"replyCount": 1,
"replyCount": 0,
"repostCount": 0,
"uri": "record(5)",
"viewer": Object {},
Expand All @@ -247,13 +203,14 @@ Object {
"$type": "app.bsky.feed.defs#threadViewPost",
"post": Object {
"author": Object {
"did": "user(4)",
"handle": "carol.test",
"avatar": "https://bsky.public.url/img/avatar/plain/user(4)/cids(1)@jpeg",
"did": "user(3)",
"displayName": "bobby",
"handle": "bob.test",
"labels": Array [],
"viewer": Object {
"blockedBy": false,
"followedBy": "record(10)",
"following": "record(9)",
"following": "record(10)",
"muted": true,
"mutedByList": Object {
"avatar": "https://bsky.public.url/img/avatar/plain/user(1)/cids(1)@jpeg",
Expand All @@ -268,13 +225,56 @@ Object {
},
},
},
"cid": "cids(6)",
"cid": "cids(5)",
"embed": Object {
"$type": "app.bsky.embed.images#view",
"images": Array [
Object {
"alt": "tests/sample-img/key-landscape-small.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(4)/cids(6)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(4)/cids(6)@jpeg",
},
],
},
"indexedAt": "1970-01-01T00:00:00.000Z",
"labels": Array [],
"labels": Array [
Object {
"cid": "cids(5)",
"cts": "1970-01-01T00:00:00.000Z",
"neg": false,
"src": "did:example:labeler",
"uri": "record(9)",
"val": "test-label",
},
Object {
"cid": "cids(5)",
"cts": "1970-01-01T00:00:00.000Z",
"neg": false,
"src": "did:example:labeler",
"uri": "record(9)",
"val": "test-label-2",
},
],
"likeCount": 0,
"record": Object {
"$type": "app.bsky.feed.post",
"createdAt": "1970-01-01T00:00:00.000Z",
"embed": Object {
"$type": "app.bsky.embed.images",
"images": Array [
Object {
"alt": "tests/sample-img/key-landscape-small.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
"ref": Object {
"$link": "cids(6)",
},
"size": 4114,
},
},
],
},
"reply": Object {
"parent": Object {
"cid": "cids(0)",
Expand All @@ -285,11 +285,11 @@ Object {
"uri": "record(0)",
},
},
"text": "of course",
"text": "hear that label_me label_me_2",
},
"replyCount": 0,
"replyCount": 1,
"repostCount": 0,
"uri": "record(8)",
"uri": "record(9)",
"viewer": Object {},
},
},
Expand Down
Loading

0 comments on commit cecc669

Please sign in to comment.