#338 20 near identical extend ttl functions in storage manager.rs should be collapsed into one generic helper fix#417
Open
Conversation
…olding for a never-built feature FIXED
…ger.rs should be collapsed into one generic helper FIXED
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Findings
Identified significant code duplication in
src/storage_manager.rs.Approximately 20 TTL extension functions reused the same 6-line pattern, differing only by:
This represented a clear DRY (Don't Repeat Yourself) violation, increasing maintenance effort and expanding the file to 585 lines.
Determined that both
StorageKeyandExtensionKeyimplementIntoVal<Env, RawVal>via#[contracttype], enabling a single generic helper to support both key types.Fix Features
Introduced a private generic helper:
to centralize the
has()check andextend_ttl()logic.Supports both
StorageKeyandExtensionKeythrough 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
IntoValandRawValimports fromsoroban_sdk; no new dependencies.Left all existing unit tests unchanged, requiring no modifications.
CLOSE #338