Skip to content

perf(metadata): paginate get_version_history to bound history reads - #1075

Open
Moonwalker-rgb wants to merge 1 commit into
MettaChain:mainfrom
Moonwalker-rgb:fix/1028-metadata-version-history-pagination
Open

perf(metadata): paginate get_version_history to bound history reads#1075
Moonwalker-rgb wants to merge 1 commit into
MettaChain:mainfrom
Moonwalker-rgb:fix/1028-metadata-version-history-pagination

Conversation

@Moonwalker-rgb

@Moonwalker-rgb Moonwalker-rgb commented Aug 27, 2026

Copy link
Copy Markdown

Closes #1028

Summary

get_version_history looped over every version ever recorded for a property on each call, so reads grew linearly with metadata churn and could eventually exceed block weight limits for long-lived properties.

Changes

contracts/metadata/src/lib.rs:

  • get_version_history(property_id, from_version, limit) now returns at most limit entries in ascending version order, starting at from_version — O(limit) storage reads per call instead of O(total versions). Callers page forward by passing the last entry's version + 1; an empty page means the end of the history.
  • Zero limit and out-of-range starts return an empty page.
  • Added a test that grows a property to 1,000 versions and asserts paged reads reconstruct the full history in ascending, contiguous order.

Verification

  • cargo test -p propchain-metadata passes (6 tests).

get_version_history scanned every recorded version on each call, so
reads grew linearly with metadata churn. Add from_version/limit
pagination so callers fetch at most O(limit) entries per call, and
assert paged reads reconstruct the full history in order. Fixes MettaChain#1028.
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@Moonwalker-rgb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Metadata get_version_history scans every version on each call: history cost grows with metadata churn

1 participant