perf: cache split("/")[0] result instead of calling twice

In both getRepositoryById and getOptimizationRepositories, the
full_name.split("/")[0] call was duplicated to derive organization
and avatarUrl. Extract once into a local variable.
This commit is contained in:
Kevin Turcios 2026-04-11 04:10:17 -05:00
parent bcaf08b508
commit f96fba76f3
2 changed files with 21 additions and 17 deletions

View file

@ -93,21 +93,24 @@ export async function getAllRepositories(
const activeRepoSet = new Set(activeRepoIds.map(r => r.repository_id))
const result = repos.map(repo => ({
id: repo.id,
github_repo_id: repo.github_repo_id,
name: repo.name,
full_name: repo.full_name,
is_private: repo.is_private,
is_active: activeRepoSet.has(repo.id),
has_github_action: repo.has_github_action,
created_at: repo.created_at,
last_optimized: repo.last_optimized,
optimizations_limit: repo.optimizations_limit,
optimizations_used: repo.optimizations_used,
organization: repo.full_name.split("/")[0],
avatarUrl: `https://github.com/${repo.full_name.split("/")[0]}.png`,
}))
const result = repos.map(repo => {
const organization = repo.full_name.split("/")[0]
return {
id: repo.id,
github_repo_id: repo.github_repo_id,
name: repo.name,
full_name: repo.full_name,
is_private: repo.is_private,
is_active: activeRepoSet.has(repo.id),
has_github_action: repo.has_github_action,
created_at: repo.created_at,
last_optimized: repo.last_optimized,
optimizations_limit: repo.optimizations_limit,
optimizations_used: repo.optimizations_used,
organization,
avatarUrl: `https://github.com/${organization}.png`,
}
})
return result
} catch (error) {

View file

@ -202,6 +202,7 @@ export const getRepositoryById = withTiming(
})
}
const organization = repo.full_name.split("/")[0]
return {
id: repo.id,
github_repo_id: repo.github_repo_id,
@ -214,8 +215,8 @@ export const getRepositoryById = withTiming(
last_optimized: repo.last_optimized,
optimizations_limit: repo.optimizations_limit,
optimizations_used: repo.optimizations_used,
organization: repo.full_name.split("/")[0],
avatarUrl: `https://github.com/${repo.full_name.split("/")[0]}.png`,
organization,
avatarUrl: `https://github.com/${organization}.png`,
membersCount: repo._count.repository_members,
}
} catch (error) {