Skip to content

Parallelized mention account lookups in PostService#1622

Merged
rmgpinto merged 1 commit intomainfrom
parallelize-mention-lookups
Mar 4, 2026
Merged

Parallelized mention account lookups in PostService#1622
rmgpinto merged 1 commit intomainfrom
parallelize-mention-lookups

Conversation

@rmgpinto
Copy link
Collaborator

@rmgpinto rmgpinto commented Mar 2, 2026

@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 65bd781a-d0ca-4ed4-b90a-3faced216efb

📥 Commits

Reviewing files that changed from the base of the PR and between 947f889 and 740c8dc.

📒 Files selected for processing (2)
  • src/post/post.service.integration.test.ts
  • src/post/post.service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/post/post.service.ts

Walkthrough

The implementation of getMentionedAccounts in src/post/post.service.ts was changed to collect FedifyMention tags into a list and resolve referenced accounts in parallel via Promise.allSettled. Per-tag resolution failures are caught and logged at debug level and skipped; only fulfilled results are converted to Mention objects that retain the tag-provided name and href. Logging for mention lookup failures was lowered from info to debug. An integration test (src/post/post.service.integration.test.ts) was added asserting getByApId returns a post containing only successfully resolved mentions when some lookups fail.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'Parallelized mention account lookups in PostService' accurately describes the main change: implementing parallel processing for mention account lookups instead of sequential resolution.
Description check ✅ Passed The description references a Linear issue (BER-3241) related to the PR objectives, demonstrating connection to the changeset's purpose, though minimal detail is provided.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch parallelize-mention-lookups

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rmgpinto rmgpinto force-pushed the parallelize-mention-lookups branch from 4282632 to 32a656f Compare March 2, 2026 09:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/post/post.service.ts (1)

138-150: Consider logging failed account lookups for debugging consistency.

The getMentionsFromContent method (lines 286-299) logs when account lookups fail, but this parallelized version silently discards failures. Adding logging would maintain consistency and help debug issues with mention resolution.

♻️ Suggested addition for logging
 const results = await Promise.allSettled(
     mentionTags.map(async (tag) => {
         const accountResult = await this.accountService.ensureByApId(
             tag.href,
         );
-        if (isError(accountResult)) return null;
+        if (isError(accountResult)) {
+            this.logger.info(
+                `Failed to lookup account for mention: ${tag.name}, error: ${getError(accountResult)}`,
+            );
+            return null;
+        }
         return {
             name: tag.name,
             href: tag.href,
             account: getValue(accountResult),
         };
     }),
 );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/post/post.service.ts` around lines 138 - 150, The parallel mention
resolution silently drops failures; update the Promise.allSettled handling in
getMentionsFromContent's parallel path (the mentionTags ->
accountService.ensureByApId flow) to log failed lookups: after awaiting
Promise.allSettled(results), iterate the settled results and for any entry that
is "rejected" or a fulfilled result where isError(accountResult) would have
returned null, call the service logger (e.g., this.logger.warn or
this.logger.error) with the tag.href and the rejection reason or error details
so failures are visible for debugging while keeping the existing behavior of
returning the filtered successes via getValue.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/post/post.service.ts`:
- Around line 138-150: The parallel mention resolution silently drops failures;
update the Promise.allSettled handling in getMentionsFromContent's parallel path
(the mentionTags -> accountService.ensureByApId flow) to log failed lookups:
after awaiting Promise.allSettled(results), iterate the settled results and for
any entry that is "rejected" or a fulfilled result where isError(accountResult)
would have returned null, call the service logger (e.g., this.logger.warn or
this.logger.error) with the tag.href and the rejection reason or error details
so failures are visible for debugging while keeping the existing behavior of
returning the filtered successes via getValue.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4282632 and 32a656f.

📒 Files selected for processing (1)
  • src/post/post.service.ts

);

return mentions;
return results
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This felt a little verbose, I wonder if we could simplify to just:

const mentions = await Promise.all(
  mentionTags.map(async ({href, name}): Promise<Mention | null> => {
    try {
      const accountResult = await this.accountService.ensureByApId(href);
      
      if (isError(accountResult)){ 
        return null;
      }
      
      return {name, href, account: getValue(accountResult)};
    } catch (err) {
      this.logger.debug(
        'Failed to look up account for mention {href}',
        { href: href.toString(), error: err },
      );

      return null;
    }
  }),
);

return mentions.filter((m): m is Mention => m !== null);

This would also let us log a failure instead of silently dropping (useful for debugging?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could be good to add a test for the best-effort behaviour change (if a lookup fails, others are still returned)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming order doesn't matter? (this could potentially return results out of the order they were passed in)

@rmgpinto rmgpinto force-pushed the parallelize-mention-lookups branch from 32a656f to 947f889 Compare March 2, 2026 18:51
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/post/post.service.ts (1)

144-147: Consider using debug level for failed mention lookups.

Failed lookups for unknown external accounts may be common and expected behavior. Using info level could create unnecessary log noise in production. Consider downgrading to debug level since these logs are primarily useful for troubleshooting.

💡 Suggested change
                     if (isError(accountResult)) {
-                        this.logger.info(
+                        this.logger.debug(
                             `Failed to lookup account for mention: ${tag.name}, error: ${getError(accountResult)}`,
                         );
                         return null;
                     }

And similarly at line 155:

                 } catch (err) {
-                    this.logger.info(
+                    this.logger.debug(
                         `Failed to lookup account for mention: ${tag.name}, error: ${err}`,
                     );
                     return null;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/post/post.service.ts` around lines 144 - 147, The log for failed external
account lookup in post.service.ts (the this.logger.info call that logs `Failed
to lookup account for mention: ${tag.name}, error: ${getError(accountResult)}`)
should be lowered to this.logger.debug because failed mention lookups are
expected; update both occurrences (the info at the lookup failure and the
similar one at the later mention handling around line 155) to use debug so you
retain the same message and getError(accountResult) details but avoid noisy
production info logs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/post/post.service.ts`:
- Around line 144-147: The log for failed external account lookup in
post.service.ts (the this.logger.info call that logs `Failed to lookup account
for mention: ${tag.name}, error: ${getError(accountResult)}`) should be lowered
to this.logger.debug because failed mention lookups are expected; update both
occurrences (the info at the lookup failure and the similar one at the later
mention handling around line 155) to use debug so you retain the same message
and getError(accountResult) details but avoid noisy production info logs.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32a656f and 947f889.

📒 Files selected for processing (2)
  • src/post/post.service.integration.test.ts
  • src/post/post.service.ts

@rmgpinto rmgpinto force-pushed the parallelize-mention-lookups branch 2 times, most recently from 952f0a9 to 825899c Compare March 3, 2026 09:45
@rmgpinto
Copy link
Collaborator Author

rmgpinto commented Mar 4, 2026

@mike182uk I've made the changes you suggested, can you re-review? Thanks

Comment on lines +144 to +146
this.logger.debug(
`Failed to lookup account for mention: ${tag.name}, error: ${getError(accountResult)}`,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably just rethrow this error and handle everything in the catch?

throw getError(accountResult)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rmgpinto rmgpinto force-pushed the parallelize-mention-lookups branch from 825899c to 740c8dc Compare March 4, 2026 15:23
@rmgpinto rmgpinto merged commit 77bf101 into main Mar 4, 2026
12 checks passed
@rmgpinto rmgpinto deleted the parallelize-mention-lookups branch March 4, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants