FilOzone / FilOzone/pdp-explorer
perf(subgraph): cut per-event store round-trips
- Dominant language
- TypeScript
- Stars
- 3
- Forks
- 7
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 4
Description
## Problem
Two guaranteed-miss Postgres lookups happen on hot paths:
1. **Transaction dedup via `Transaction.load()`** in every handler (`handleDataSetCreated`, `handleDataSetDeleted`, `handleStorageProviderChanged`, `handlePossessionProven`, `handleNextProvingPeriod`, `handlePiecesAdded` in `subgraph/src/pdp-verifier.ts`). A transaction's events are always processed within one block, so the entity can only pre-exist in the **in-block cache** — but `load()` on a not-yet-existing entity is a guaranteed DB round-trip for the first event of each tx.
2. **`Root.load()` existence check** in `handlePiecesAdded` (`pdp-verifier.ts:1109-1116`). The contract's `nextPieceId` is monotonic — piece IDs are never reused — and the code's own log message says "This shouldn't happen." That's one DB miss per piece added during backfill.
## Proposal
- Replace `Transaction.load(id)` with `Transaction.loadInBlock(id)` at all sites (apiVersion is 0.0.9, so it's available). This is the documented use case for `loadInBlock`: entities created earlier in the same block.
- Drop the `Root.load` existence check and construct the Root unconditionally.
## Acceptance criteria
- [ ] No `Transaction.load()` remains in `pdp-verifier.ts`
- [ ] No existence check before Root creation in `handlePiecesAdded`
- [ ] Tests pass (multi-event-per-tx fixtures still produce a single Transaction entity)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in subgraph/src/pdp-verifier.ts and inspect the listed event handlers, especially handlePiecesAdded around lines 1109-1116. Check the existing multi-event-per-transaction fixtures and run the test suite; done means no Transaction.load() remains, Root is created without the existence check, and fixtures still produce one Transaction entity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- backend, database, performance
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100