Skip to content

#338 20 near identical extend ttl functions in storage manager.rs should be collapsed into one generic helper fix#417

Open
Priest-Codes wants to merge 2 commits into
HubDApp:mainfrom
Priest-Codes:#338--20-near-identical-extend_-_ttl-functions-in-storage_manager.rs-should-be-collapsed-into-one-generic-helper-FIX
Open

#338 20 near identical extend ttl functions in storage manager.rs should be collapsed into one generic helper fix#417
Priest-Codes wants to merge 2 commits into
HubDApp:mainfrom
Priest-Codes:#338--20-near-identical-extend_-_ttl-functions-in-storage_manager.rs-should-be-collapsed-into-one-generic-helper-FIX

Conversation

@Priest-Codes

Copy link
Copy Markdown

Findings

  • Identified significant code duplication in src/storage_manager.rs.

  • Approximately 20 TTL extension functions reused the same 6-line pattern, differing only by:

    • Storage key variant
    • Threshold constant
    • TTL bump constant
  • This represented a clear DRY (Don't Repeat Yourself) violation, increasing maintenance effort and expanding the file to 585 lines.

  • Determined that both StorageKey and ExtensionKey implement IntoVal<Env, RawVal> via #[contracttype], enabling a single generic helper to support both key types.

Fix Features

  • Introduced a private generic helper:

    extend_if_exists<K: IntoVal<Env, RawVal>>(env, key, threshold, bump)

    to centralize the has() check and extend_ttl() logic.

  • Supports both StorageKey and ExtensionKey through the generic trait bound.

  • Refactored 18 simple functions into one-line calls to the helper.

  • Updated 5 multi-key functions to reuse the helper for each key operation while preserving existing logic.

  • Modified only one file: src/storage_manager.rs.

  • Preserved all 29 public function names, parameters, and return types.

  • Kept the helper private within impl StorageManager.

  • Reduced file size from 585 to 482 lines, saving ~103 lines (17.6%).

  • Added only the required IntoVal and RawVal imports from soroban_sdk; no new dependencies.

  • Left all existing unit tests unchanged, requiring no modifications.

CLOSE #338

…ger.rs should be collapsed into one generic helper FIXED
@drips-wave

drips-wave Bot commented Jul 23, 2026

Copy link
Copy Markdown

@Priest-Codes 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.

~20 near-identical extend_*_ttl functions in storage_manager.rs should be collapsed into one generic helper

1 participant