fix: list metadata return stream id and provider address#1142
Conversation
WalkthroughReworks SQL action list_metadata_by_height: updates signature to include from/to height, replaces stream_ref with stream_id and adds data_provider, qualifies columns via aliases, and joins metadata with streams and data_providers. Filters and ordering now use m.created_at, and predicates reference m.value_ref and m.disabled_at. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant DB
participant Action as list_metadata_by_height
participant M as metadata (m)
participant S as streams (s)
participant DP as data_providers (dp)
Client->>DB: CALL list_metadata_by_height($ref, $key, $from_height, $to_height, ...)
DB->>Action: Invoke
rect rgba(200,230,255,0.25)
note right of Action: Validate height range ($from_height..$to_height)
end
Action->>M: SELECT ... FROM metadata m
Action->>S: JOIN streams s ON s.id = m.stream_ref
Action->>DP: JOIN data_providers dp ON dp.id = s.data_provider_id
Action->>Action: Apply filters: m.value_ref = $ref, m.key = $key, m.disabled_at IS NULL, m.created_at in range
Action-->>Client: rows(stream_id, data_provider, key, value, m.created_at, ...)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Bug Report Checklist
|
|
@pr-time-tracker bug commit 7ac741c && bug author @williamrusdyputra |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (6)
internal/migrations/021-metadata-actions.sql (6)
73-76: Inner JOINs drop orphaned metadata; switch to LEFT JOIN if desirable.If any metadata rows can exist with missing
streamsordata_providers, the current INNER JOIN will exclude them. If you prefer to still return such rows (with nullstream_id/data_provider), use LEFT JOINs.Apply if desired:
- JOIN streams s ON s.id = m.stream_ref - JOIN data_providers dp ON dp.id = s.data_provider_id + LEFT JOIN streams s ON s.id = m.stream_ref + LEFT JOIN data_providers dp ON dp.id = s.data_provider_id
76-76: Qualify column for consistency and to avoid future ambiguity.Prefer
m.metadata_keyover the unqualifiedmetadata_key.- WHERE metadata_key = $key + WHERE m.metadata_key = $key
79-79: Make ref filter index-friendly; normalize the param once.
ORmakes the predicate less sargable. Normalize$refonce and compare directly; this preserves the index onm.value_ref.- AND ($ref IS NULL OR m.value_ref = LOWER($ref)) + AND ($ref IS NULL OR m.value_ref = $ref)Add early normalization:
@@ $current_block INT8 := @height; @@ + if $ref IS NOT NULL { + $ref := LOWER($ref); + }
82-83: Stabilize pagination order with a tiebreaker.Multiple rows can share the same
created_at. Add a secondary key for deterministic paging.- ORDER BY m.created_at ASC + ORDER BY m.created_at ASC, row_id ASC
1-16: Doc nit: stray punctuation in params comment.Minor typo on Line 8 (
*.). Clean up for clarity.- *. $ref: filter by value reference. + * $ref: filter by value reference.
63-83: Indexes to support new access pattern (ops follow-up).To keep this fast under load, consider:
- Index on metadata(metadata_key, created_at) where disabled_at is null
- Index on metadata(value_ref) if not already present
- Index on streams(id) and data_providers(id) exist (PK), but ensure streams(data_provider_id) is indexed
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
internal/migrations/021-metadata-actions.sql(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: acceptance-test
🔇 Additional comments (4)
internal/migrations/021-metadata-actions.sql (4)
25-26: API surface change: new columnsstream_id,data_provider(client impact).This breaks the previous return shape (replacing
stream_ref). Please confirm all callers, views, and downstream integrations (e.g., trufscan) are updated to consume the new columns and ordering.
64-66: Validate selected fields match external contract.Confirm
s.stream_idis the intended external identifier anddp.addressis indeed the “provider address” the UI expects. If a checksum/normalized format is required, normalize here.
80-81: Confirmm.created_atis block height, not a timestamp.The action treats
created_atas an INT8 height. If it’s a timestamp elsewhere, switch to the actual height column to avoid incorrect filtering.
35-49: Good: sane defaults and non-negative guards for limit/offset.Solid defensive handling for pagination inputs.
Time Submission Status
|
|
bypassing for now, as this is outside work hours, I already reported the bug |
Related Problem
related: https://github.com/trufnetwork/trufscan/issues/32#event-19521484138
How Has This Been Tested?
Summary by CodeRabbit
New Features
Refactor