perf: Add timeout and optimize URL unfurl performance (#11149)

* perf: Add timeout and optimize URL unfurl performance

Fixes issue where urls.unfurl endpoint could take 15+ seconds due to external API timeouts and sequential plugin execution.

Changes:
- Add timeout support to fetch utility with AbortController (defaults to no timeout, configurable per request)
- Add 10 second timeout to Iframely plugin requests
- Add early URL pattern validation to GitHub and Linear plugins to avoid unnecessary database queries
- Add try-catch error handling to URL parsing in GitHub and Linear plugins

This reduces worst-case unfurl time from 15+ seconds to ~10 seconds maximum, and eliminates unnecessary overhead for URLs that don't match plugin patterns.

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

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

* lint

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Tom MoorandClaude Sonnet 4.5 authored and GitHub committed 2026-01-10 18:03:19 -05:00
1 parent 23d4374cb0
commit bcee4893f4
4 files changed
+67 -32

No files matched your search

+22 -16
View File
@@ -140,24 +140,29 @@ export class GitHub {
* @returns {object} Containing resource identifiers - `owner`, `repo`, `type` and `id`.
*/
public static parseUrl(url: string) {
const { hostname, pathname } = new URL(url);
if (hostname !== "github.com") {
try {
const { hostname, pathname } = new URL(url);
if (hostname !== "github.com") {
return;
}
const parts = pathname.split("/");
const owner = parts[1];
const repo = parts[2];
const type = parts[3]
? (pluralize.singular(parts[3]) as UnfurlResourceType)
: undefined;
const id = Number(parts[4]);
if (!type || !GitHub.supportedResources.includes(type)) {
return;
}
return { owner, repo, type, id, url };
} catch (_err) {
// Invalid URL format
return;
}
const parts = pathname.split("/");
const owner = parts[1];
const repo = parts[2];
const type = parts[3]
? (pluralize.singular(parts[3]) as UnfurlResourceType)
: undefined;
const id = Number(parts[4]);
if (!type || !GitHub.supportedResources.includes(type)) {
return;
}
return { owner, repo, type, id, url };
}
private static authenticateAsApp = () => {
@@ -222,6 +227,7 @@ export class GitHub {
* @returns An object containing resource details e.g, a GitHub Pull Request details
*/
public static unfurl: UnfurlSignature = async (url: string, actor: User) => {
// Early return if URL doesn't match GitHub pattern (before any DB queries)
const resource = GitHub.parseUrl(url);
if (!resource) {