mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
perf(mobile): build the two projected git enums once, not per parse (#21311)
`readProjectedConflictOperation` and `readProjectedCompareStatus` constructed a `z.enum` on every call, so every `git.status` and `git.branchCompare` reply paid the constructor. Hoisted to module constants; the git-status payload schema reuses the same instance. Behaviour is unchanged: same arms, same fallbacks, identical reader output on all eleven recorded matrix cases. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
This commit is contained in:
@@ -27,6 +27,9 @@ const GIT_BRANCH_COMPARE_STATUS = [
|
||||
|
||||
type GitBranchCompareStatus = (typeof GIT_BRANCH_COMPARE_STATUS)[number]
|
||||
|
||||
// Built once: readProjectedCompareStatus runs on every reply.
|
||||
const gitBranchCompareStatusSchema = z.enum(GIT_BRANCH_COMPARE_STATUS)
|
||||
|
||||
/**
|
||||
* One committed change.
|
||||
*
|
||||
@@ -101,7 +104,7 @@ export const branchCompareProjectionSchema: z.ZodType<MobileGitBranchCompareResu
|
||||
// Main coerced an unreadable compare status to 'error' rather than dropping the reply, and the
|
||||
// summary line renders off that value, so the coercion is the behaviour rather than a defect.
|
||||
function readProjectedCompareStatus(value: unknown): GitBranchCompareStatus {
|
||||
const parsed = z.enum(GIT_BRANCH_COMPARE_STATUS).safeParse(value)
|
||||
const parsed = gitBranchCompareStatusSchema.safeParse(value)
|
||||
return parsed.success ? parsed.data : 'error'
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ const GIT_CONFLICT_KIND = [
|
||||
] as const
|
||||
const GIT_CONFLICT_OPERATION = ['merge', 'rebase', 'cherry-pick', 'unknown'] as const
|
||||
|
||||
// Built once: readProjectedConflictOperation runs on every reply.
|
||||
const gitConflictOperationSchema = z.enum(GIT_CONFLICT_OPERATION)
|
||||
|
||||
/**
|
||||
* One working-tree entry.
|
||||
*
|
||||
@@ -70,7 +73,7 @@ const gitUpstreamStatusSchema = z.looseObject({
|
||||
*/
|
||||
export const gitStatusHostPayloadSchema = z.looseObject({
|
||||
entries: salvagingArray(gitStatusEntrySchema),
|
||||
conflictOperation: salvagedOptional('conflictOperation', z.enum(GIT_CONFLICT_OPERATION)),
|
||||
conflictOperation: salvagedOptional('conflictOperation', gitConflictOperationSchema),
|
||||
branch: salvagedOptional('branch', z.string()),
|
||||
head: salvagedOptional('head', z.string()),
|
||||
upstreamStatus: salvagedOptional('upstreamStatus', gitUpstreamStatusSchema)
|
||||
@@ -168,6 +171,6 @@ export const gitStatusProjectionSchema: z.ZodType<MobileGitStatusProjection | nu
|
||||
// Main coerced an unreadable operation to 'unknown' rather than dropping the reply; four screens
|
||||
// render off that value, so the coercion is the behaviour, not a defect.
|
||||
function readProjectedConflictOperation(value: unknown): GitConflictOperation {
|
||||
const parsed = z.enum(GIT_CONFLICT_OPERATION).safeParse(value)
|
||||
const parsed = gitConflictOperationSchema.safeParse(value)
|
||||
return parsed.success ? parsed.data : 'unknown'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user