Skip to content

Commit

Permalink
Appview: sync-up protos for quotes and postgates (bluesky-social#2733)
Browse files Browse the repository at this point in the history
appview: sync-up protos for quotes and postgates
  • Loading branch information
devinivy authored Aug 22, 2024
1 parent 47263e9 commit 45770bb
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 210 deletions.
53 changes: 30 additions & 23 deletions packages/bsky/proto/bsky.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ message GetThreadGateRecordsResponse {
repeated Record records = 1;
}

message GetPostGateRecordsRequest {
message GetPostgateRecordsRequest {
repeated string uris = 1;
}

message GetPostGateRecordsResponse {
message GetPostgateRecordsResponse {
repeated Record records = 1;
}

Expand Down Expand Up @@ -231,6 +231,17 @@ message GetLikesBySubjectSortedResponse {
string cursor = 2;
}

message GetQuotesBySubjectSortedRequest {
RecordRef subject = 1;
int32 limit = 2;
string cursor = 3;
}

message GetQuotesBySubjectSortedResponse {
repeated string uris = 1;
string cursor = 2;
}

// - return like uris for user A on subject B, C, D...
// - viewer state on posts
message GetLikesByActorAndSubjectsRequest {
Expand Down Expand Up @@ -260,23 +271,6 @@ message GetActorLikesResponse {
string cursor = 2;
}

//
// Quotes
//

message GetQuotesBySubjectRequest {
RecordRef subject = 1;
int32 limit = 2;
string cursor = 3;
}

message GetQuotesBySubjectResponse {
repeated RecordRef refs = 1;
string cursor = 2;
}

// - return post uris that quote the given subject uri

//
// Interactions
//
Expand Down Expand Up @@ -322,6 +316,15 @@ message GetListCountsResponse {
repeated int32 list_items = 1;
}

message GetNewUserCountForRangeRequest {
google.protobuf.Timestamp start = 1;
google.protobuf.Timestamp end = 2;
}

message GetNewUserCountForRangeResponse {
int32 count = 1;
}

//
// Reposts
//
Expand Down Expand Up @@ -597,7 +600,6 @@ message GetThreadMutesOnSubjectsResponse {
repeated bool muted = 1;
}


//
// Blocks
//
Expand Down Expand Up @@ -1059,15 +1061,19 @@ message GetRecordTakedownResponse {

// Polo-backed Graph Endpoints

// GetFollowsFollowing gets the list of DIDs that the actor follows that also follow the target


// GetFollowsFollowing gets the list of DIDs that the actor follows that also follow the targets
message GetFollowsFollowingRequest {
string actor_did = 1;
repeated string target_dids = 2;
}

message FollowsFollowing {
string target_did = 1;
repeated string dids = 2;
}

message GetFollowsFollowingResponse {
repeated FollowsFollowing results = 1;
}
Expand Down Expand Up @@ -1097,7 +1103,7 @@ service Service {
rpc GetActorChatDeclarationRecords(GetActorChatDeclarationRecordsRequest) returns (GetActorChatDeclarationRecordsResponse);
rpc GetRepostRecords(GetRepostRecordsRequest) returns (GetRepostRecordsResponse);
rpc GetThreadGateRecords(GetThreadGateRecordsRequest) returns (GetThreadGateRecordsResponse);
rpc GetPostGateRecords(GetPostGateRecordsRequest) returns (GetPostGateRecordsResponse);
rpc GetPostgateRecords(GetPostgateRecordsRequest) returns (GetPostgateRecordsResponse);
rpc GetLabelerRecords(GetLabelerRecordsRequest) returns (GetLabelerRecordsResponse);
rpc GetStarterPackRecords(GetStarterPackRecordsRequest) returns (GetStarterPackRecordsResponse);

Expand All @@ -1118,13 +1124,14 @@ service Service {
rpc GetActorReposts(GetActorRepostsRequest) returns (GetActorRepostsResponse);

// Quotes
rpc GetQuotesBySubject(GetQuotesBySubjectRequest) returns (GetQuotesBySubjectResponse);
rpc GetQuotesBySubjectSorted(GetQuotesBySubjectSortedRequest) returns (GetQuotesBySubjectSortedResponse);

// Interaction Counts
rpc GetInteractionCounts(GetInteractionCountsRequest) returns (GetInteractionCountsResponse);
rpc GetCountsForUsers(GetCountsForUsersRequest) returns (GetCountsForUsersResponse);
rpc GetStarterPackCounts(GetStarterPackCountsRequest) returns (GetStarterPackCountsResponse);
rpc GetListCounts(GetListCountsRequest) returns (GetListCountsResponse);
rpc GetNewUserCountForRange(GetNewUserCountForRangeRequest) returns (GetNewUserCountForRangeResponse);

// Profile
rpc GetActors(GetActorsRequest) returns (GetActorsResponse);
Expand Down
23 changes: 13 additions & 10 deletions packages/bsky/src/api/app/bsky/feed/getQuotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { Views } from '../../../../views'
import { mapDefined } from '@atproto/common'
import { QueryParams } from '../../../../lexicon/types/app/bsky/feed/getQuotes'
import { ItemRef, parseString } from '../../../../hydration/util'
import { parseString } from '../../../../hydration/util'

export default function (server: Server, ctx: AppContext) {
const getQuotes = createPipeline(skeleton, hydration, noBlocks, presentation)
Expand Down Expand Up @@ -40,15 +40,15 @@ const skeleton = async (inputs: {
}): Promise<Skeleton> => {
const { ctx, params } = inputs
if (clearlyBadCursor(params.cursor)) {
return { refs: [] }
return { uris: [] }
}
const quotesRes = await ctx.hydrator.dataplane.getQuotesBySubject({
const quotesRes = await ctx.hydrator.dataplane.getQuotesBySubjectSorted({
subject: { uri: params.uri, cid: params.cid },
cursor: params.cursor,
limit: params.limit,
})
return {
refs: quotesRes.refs,
uris: quotesRes.uris,
cursor: parseString(quotesRes.cursor),
}
}
Expand All @@ -59,7 +59,10 @@ const hydration = async (inputs: {
skeleton: Skeleton
}) => {
const { ctx, params, skeleton } = inputs
return await ctx.hydrator.hydratePosts(skeleton.refs, params.hydrateCtx)
return await ctx.hydrator.hydratePosts(
skeleton.uris.map((uri) => ({ uri })),
params.hydrateCtx,
)
}

const noBlocks = (inputs: {
Expand All @@ -68,8 +71,8 @@ const noBlocks = (inputs: {
hydration: HydrationState
}) => {
const { ctx, skeleton, hydration } = inputs
skeleton.refs = skeleton.refs.filter((ref) => {
return !ctx.views.viewerBlockExists(ref.uri, hydration)
skeleton.uris = skeleton.uris.filter((uri) => {
return !ctx.views.viewerBlockExists(uri, hydration)
})
return skeleton
}
Expand All @@ -81,8 +84,8 @@ const presentation = (inputs: {
hydration: HydrationState
}) => {
const { ctx, params, skeleton, hydration } = inputs
const postViews = mapDefined(skeleton.refs, (ref) => {
return ctx.views.post(ref.uri, hydration)
const postViews = mapDefined(skeleton.uris, (uri) => {
return ctx.views.post(uri, hydration)
})
return {
posts: postViews,
Expand All @@ -100,6 +103,6 @@ type Context = {
type Params = QueryParams & { hydrateCtx: HydrateCtx }

type Skeleton = {
refs: ItemRef[]
uris: string[]
cursor?: string
}
4 changes: 2 additions & 2 deletions packages/bsky/src/data-plane/server/routes/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Database } from '../db'
import { paginate, TimeCidKeyset } from '../db/pagination'

export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({
async getQuotesBySubject(req) {
async getQuotesBySubjectSorted(req) {
const { subject, cursor, limit } = req
const { ref } = db.db.dynamic

Expand All @@ -25,7 +25,7 @@ export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({
const quotes = await builder.execute()

return {
refs: quotes.map((q) => ({ uri: q.uri, cid: q.cid })),
uris: quotes.map((q) => q.uri),
cursor: keyset.packFromResult(quotes),
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/src/data-plane/server/routes/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({
getProfileRecords: getRecords(db, ids.AppBskyActorProfile),
getRepostRecords: getRecords(db, ids.AppBskyFeedRepost),
getThreadGateRecords: getRecords(db, ids.AppBskyFeedThreadgate),
getPostGateRecords: getRecords(db, ids.AppBskyFeedPostgate),
getPostgateRecords: getRecords(db, ids.AppBskyFeedPostgate),
getLabelerRecords: getRecords(db, ids.AppBskyLabelerService),
getActorChatDeclarationRecords: getRecords(db, ids.ChatBskyActorDeclaration),
getStarterPackRecords: getRecords(db, ids.AppBskyGraphStarterpack),
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/src/hydration/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class FeedHydrator {
uris: string[],
includeTakedowns = false,
): Promise<Postgates> {
const res = await this.dataplane.getPostGateRecords({ uris })
const res = await this.dataplane.getPostgateRecords({ uris })
return uris.reduce((acc, uri, i) => {
const record = parseRecord<PostgateRecord>(
res.records[i],
Expand Down
39 changes: 25 additions & 14 deletions packages/bsky/src/proto/bsky_connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,22 @@ import {
GetMutelistSubscriptionsResponse,
GetMutesRequest,
GetMutesResponse,
GetNewUserCountForRangeRequest,
GetNewUserCountForRangeResponse,
GetNotificationSeenRequest,
GetNotificationSeenResponse,
GetNotificationsRequest,
GetNotificationsResponse,
GetPostGateRecordsRequest,
GetPostGateRecordsResponse,
GetPostgateRecordsRequest,
GetPostgateRecordsResponse,
GetPostRecordsRequest,
GetPostRecordsResponse,
GetPostReplyCountsRequest,
GetPostReplyCountsResponse,
GetProfileRecordsRequest,
GetProfileRecordsResponse,
GetQuotesBySubjectRequest,
GetQuotesBySubjectResponse,
GetQuotesBySubjectSortedRequest,
GetQuotesBySubjectSortedResponse,
GetRecordTakedownRequest,
GetRecordTakedownResponse,
GetRelationshipsRequest,
Expand Down Expand Up @@ -314,12 +316,12 @@ export const Service = {
kind: MethodKind.Unary,
},
/**
* @generated from rpc bsky.Service.GetPostGateRecords
* @generated from rpc bsky.Service.GetPostgateRecords
*/
getPostGateRecords: {
name: 'GetPostGateRecords',
I: GetPostGateRecordsRequest,
O: GetPostGateRecordsResponse,
getPostgateRecords: {
name: 'GetPostgateRecords',
I: GetPostgateRecordsRequest,
O: GetPostgateRecordsResponse,
kind: MethodKind.Unary,
},
/**
Expand Down Expand Up @@ -439,12 +441,12 @@ export const Service = {
/**
* Quotes
*
* @generated from rpc bsky.Service.GetQuotesBySubject
* @generated from rpc bsky.Service.GetQuotesBySubjectSorted
*/
getQuotesBySubject: {
name: 'GetQuotesBySubject',
I: GetQuotesBySubjectRequest,
O: GetQuotesBySubjectResponse,
getQuotesBySubjectSorted: {
name: 'GetQuotesBySubjectSorted',
I: GetQuotesBySubjectSortedRequest,
O: GetQuotesBySubjectSortedResponse,
kind: MethodKind.Unary,
},
/**
Expand Down Expand Up @@ -485,6 +487,15 @@ export const Service = {
O: GetListCountsResponse,
kind: MethodKind.Unary,
},
/**
* @generated from rpc bsky.Service.GetNewUserCountForRange
*/
getNewUserCountForRange: {
name: 'GetNewUserCountForRange',
I: GetNewUserCountForRangeRequest,
O: GetNewUserCountForRangeResponse,
kind: MethodKind.Unary,
},
/**
* Profile
*
Expand Down
Loading

0 comments on commit 45770bb

Please sign in to comment.