apex-dev-tools / apex-dev-tools/apex-log-parser

✨ feat: Typed per-kind event indexes and a public tree visitor

Open
#34 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
2
Forks
0
Avg merge
5h 51m
Merged PRs (30d)
32

Description

### Problem

The parser already builds `eventIndex` and `eventsById`, but exposes no way to reach the events of one
kind, so every consumer writes its own recursive walk:

- Analyzer `log-viewer/src/features/database/services/Database.ts:61,80,100` — three near-identical
walks: `getSOQLLines`, `getDMLLines`, `getSOSLLines`.
- MCP `src/tools/apexLogSource.ts:156-163` — a generic `walkLog`, used by `queryPlans.ts`,
`listLimitRisks.ts` and the operation tools, each filtering on a raw type string such as
`node.type !== "SOQL_EXECUTE_BEGIN"`.

Each walk re-traverses the whole tree, after the parser has already visited every node.

### Proposed solution

- Typed per-kind indexes on `ApexLog`: `soqlEvents`, `dmlEvents`, `soslEvents`, and a general
`eventsByType` map. Populate during the existing traversal, so there is no extra pass.
- A public tree visitor, so a consumer with a kind the parser does not index does not have to
hand-roll recursion. Iterative, not recursive — a deep log must not overflow the stack.

Decide whether the indexes hold events or ids: ids keep the retained size down, and `eventsById`
already exists to resolve them.

#### Acceptance

- `Database.ts` can delete its three walks.
- MCP can delete `walkLog` for the indexed kinds.
- No measurable parse-time regression (see the performance issue for the harness).

### Alternatives considered

_None recorded._

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.