WIP PWA for Grain
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: simplify getFollowing to use actorHandle filter

Reduces from 3 queries to 2 by filtering follows directly by actorHandle
instead of first looking up the DID.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+6 -23
+6 -23
src/services/grain-api.js
··· 276 276 } 277 277 278 278 async getFollowing(handle, { first = 20, after = null } = {}) { 279 - // First get the user's DID 280 - const profileQuery = ` 281 - query GetDid($handle: String!) { 282 - socialGrainActorProfile(first: 1, where: { actorHandle: { eq: $handle } }) { 283 - edges { 284 - node { did } 285 - } 286 - } 287 - } 288 - `; 289 - const profileResponse = await this.#execute(profileQuery, { handle }); 290 - const did = profileResponse.data?.socialGrainActorProfile?.edges?.[0]?.node?.did; 291 - 292 - if (!did) { 293 - return { profiles: [], pageInfo: { hasNextPage: false, endCursor: null }, totalCount: 0 }; 294 - } 295 - 296 - // Query following (people this user follows) 297 - const followQuery = ` 298 - query GetFollowing($did: String!, $first: Int, $after: String) { 279 + // Query follows by actorHandle directly 280 + const query = ` 281 + query GetFollowing($handle: String!, $first: Int, $after: String) { 299 282 socialGrainGraphFollow( 300 283 first: $first 301 284 after: $after 302 - where: { did: { eq: $did } } 285 + where: { actorHandle: { eq: $handle } } 303 286 sortBy: [{ field: createdAt, direction: DESC }] 304 287 ) { 305 288 edges { ··· 316 299 } 317 300 `; 318 301 319 - const followResponse = await this.#execute(followQuery, { did, first, after }); 320 - const connection = followResponse.data?.socialGrainGraphFollow; 302 + const response = await this.#execute(query, { handle, first, after }); 303 + const connection = response.data?.socialGrainGraphFollow; 321 304 const subjectDids = connection?.edges?.map(e => e.node.subject).filter(Boolean) || []; 322 305 323 306 if (subjectDids.length === 0) {