fix: replace CampaignApplicants Vec with O(1) ApplicantCount storage - #50
Merged
JamesVictor-O merged 1 commit intoJul 25, 2026
Merged
Conversation
storage::add_campaign_applicant rewrote an ever-growing Vec<Address> on every apply_to_campaign call just to answer a yes/no question in has_campaign_applicants. Replace it with a u32 counter under DataKey::ApplicantCount, matching the existing approved_count pattern on Campaign, so applying costs O(1) storage-writes regardless of how many creators already applied. Adds a regression test that applies 200+ creators and asserts the storage write cost of a later apply matches an early one, plus that update_campaign_metadata's lock-after-first-application behavior from Ads-Bazaar#38 is unaffected.
4 tasks
Contributor
|
Merged, nice fix — clean root cause and a genuinely good regression test. Measuring env.cost_estimate().resources().write_bytes before/after 200 applicants to prove O(1) cost, rather than just asserting behavioral equivalence, is exactly the right way to guard against this class of regression sneaking back in. Verified before merging: fmt, full workspace build, all 64 tests, clippy -D warnings, and the wasm32v1-none release build. Also confirmed via git merge-tree that this combines cleanly with #34 and #49 (both landed after your branch was cut) — no conflicts, no follow-up fix needed. CI is green on main: https://github.com/Ads-Bazaar/ads-bazaar-contract/actions/runs/30163010137 |
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.
storage::add_campaign_applicant rewrote an ever-growing Vec
on every apply_to_campaign call just to answer a yes/no question in has_campaign_applicants. Replace it with a u32 counter under DataKey::ApplicantCount, matching the existing approved_count pattern on Campaign, so applying costs O(1) storage-writes regardless of how many creators already applied.Adds a regression test that applies 200+ creators and asserts the storage write cost of a later apply matches an early one, plus that update_campaign_metadata's lock-after-first-application behavior from #38 is unaffected.
Closes #43