Skip to content

Use local DB for fetching dotrain source #2446

@findolor

Description

@findolor

Summary

fetch_dotrain_source() currently always queries the metaboard subgraph to resolve dotrain source code from a dotrain_hash. With metaboard events now indexed locally (see #2445), the function should check the local DB first and only fall back to the subgraph when the data isn't available locally.

Problem

Even when the local DB is available and fully synced, every call to fetch_dotrain_source() makes a network request to the metaboard subgraph. This adds latency and creates an unnecessary dependency on an external service when the data is already present in the local meta_events table.

Proposed Change

Update fetch_dotrain_source() to follow the same "local first, remote fallback" pattern already used by get_order_by_hash():

  1. Query the local DB meta_events table by (chain_id, subject) where subject is the dotrain_hash
  2. If found, CBOR-decode the meta bytes and extract the DotrainSourceV1
  3. If not found or local DB is unavailable, fall back to the existing metaboard subgraph query

Depends on

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions