Skip to content

Commit

Permalink
Resolve facets in parallel (bluesky-social#2957)
Browse files Browse the repository at this point in the history
* Detect facets in parallel

* Add changeset
  • Loading branch information
gaearon authored Nov 8, 2024
1 parent 124eaee commit b6eeb81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-trees-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/api": patch
---

Detect facets in parallel
16 changes: 11 additions & 5 deletions packages/api/src/rich-text/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,23 @@ export class RichText {
async detectFacets(agent: AtpBaseClient) {
this.facets = detectFacets(this.unicodeText)
if (this.facets) {
const promises: Promise<void>[] = []
for (const facet of this.facets) {
for (const feature of facet.features) {
if (AppBskyRichtextFacet.isMention(feature)) {
const did = await agent.com.atproto.identity
.resolveHandle({ handle: feature.did })
.catch((_) => undefined)
.then((res) => res?.data.did)
feature.did = did || ''
promises.push(
agent.com.atproto.identity
.resolveHandle({ handle: feature.did })
.then((res) => res?.data.did)
.catch((_) => undefined)
.then((did) => {
feature.did = did || ''
}),
)
}
}
}
await Promise.allSettled(promises)
this.facets.sort(facetSort)
}
}
Expand Down

0 comments on commit b6eeb81

Please sign in to comment.