Skip to content

fix: list metadata return stream id and provider address#1142

Merged
williamrusdyputra merged 1 commit into
mainfrom
fix/metadata-action
Sep 5, 2025
Merged

fix: list metadata return stream id and provider address#1142
williamrusdyputra merged 1 commit into
mainfrom
fix/metadata-action

Conversation

@williamrusdyputra
Copy link
Copy Markdown
Contributor

@williamrusdyputra williamrusdyputra commented Sep 5, 2025

Related Problem

related: https://github.com/trufnetwork/trufscan/issues/32#event-19521484138

How Has This Been Tested?

Screenshot 2025-09-05 at 17 23 49

Summary by CodeRabbit

  • New Features

    • list_metadata_by_height now supports height-range filtering with from_height and to_height parameters.
    • Results include richer context: stream_id and data_provider are returned.
    • Filtering and ordering use the metadata creation time for more precise results.
  • Refactor

    • Output schema updated: stream_ref column replaced by stream_id; added data_provider.
    • Consistent column qualification and ordering by creation time across results.

@williamrusdyputra williamrusdyputra self-assigned this Sep 5, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 5, 2025

Walkthrough

Reworks 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

Cohort / File(s) Summary of changes
Metadata listing action update
internal/migrations/021-metadata-actions.sql
Modified action signature to add $from_height INT8, $to_height INT8. Return columns updated: replaced stream_ref INT with stream_id TEXT and added data_provider TEXT. SELECT/WHERE/ORDER BY now qualify via m.; joins added: streams s and data_providers dp. Time and ref filters use m.created_at and m.value_ref; m.disabled_at check adjusted.

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, ...)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: view list metadata by height #1141 — Introduces the list_metadata_by_height action and its initial parameters/return shape; current PR revises it to join streams/data_providers and change returned columns.

Suggested reviewers

  • MicBun

Poem

A hop through heights, a trail of streams,
I nose the joins, decode the schemes.
From refs to IDs, providers in sight,
I thump the ground—context feels right.
With ordered steps by created-at time,
I nibble results, crisp and sublime. 🥕🐇

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/metadata-action

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@holdex
Copy link
Copy Markdown

holdex Bot commented Sep 5, 2025

Bug Report Checklist

Status Commit Link Bug Author
✅ Submitted commit link @williamrusdyputra

@williamrusdyputra
Copy link
Copy Markdown
Contributor Author

williamrusdyputra commented Sep 5, 2025

@pr-time-tracker bug commit 7ac741c && bug author @williamrusdyputra

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 streams or data_providers, the current INNER JOIN will exclude them. If you prefer to still return such rows (with null stream_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_key over the unqualified metadata_key.

-            WHERE metadata_key = $key
+            WHERE m.metadata_key = $key

79-79: Make ref filter index-friendly; normalize the param once.

OR makes the predicate less sargable. Normalize $ref once and compare directly; this preserves the index on m.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.

📥 Commits

Reviewing files that changed from the base of the PR and between 7ac741c and 69bb064.

📒 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 columns stream_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_id is the intended external identifier and dp.address is indeed the “provider address” the UI expects. If a checksum/normalized format is required, normalize here.


80-81: Confirm m.created_at is block height, not a timestamp.

The action treats created_at as 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.

@holdex
Copy link
Copy Markdown

holdex Bot commented Sep 5, 2025

Time Submission Status

Member Status Time Action Last Update
williamrusdyputra ✅ Submitted 20min Update time Sep 5, 2025, 10:27 AM

@williamrusdyputra williamrusdyputra changed the title fix: metadata return stream id and provider address fix: list metadata return stream id and provider address Sep 5, 2025
@williamrusdyputra
Copy link
Copy Markdown
Contributor Author

bypassing for now, as this is outside work hours, I already reported the bug

@williamrusdyputra williamrusdyputra merged commit 4de8a4e into main Sep 5, 2025
7 of 8 checks passed
@williamrusdyputra williamrusdyputra deleted the fix/metadata-action branch September 5, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant