Problem Statement
The Soroban contract's list_gists_by_cell function iterates over all gist IDs from the cursor to the total count, checking each gist's location_cell for a match. This is an O(n) scan that becomes prohibitively expensive (in terms of computation and fee) as the number of gists grows.
Evidence
contracts/src/lib.rs lines 66-85: for id in start..=total { ... if gist.location_cell == location_cell { ... } }
- No mapping from location_cell to gist IDs exists
- Contract iterates over every gist regardless of cell
Impact
Contract becomes unusable at scale. Transaction fees increase linearly with total gist count, not with the result set size. Users will be priced out of querying their local area.
Proposed Solution
- Add a storage mapping:
Map<String, Vec<u64>> mapping location_cell to list of gist IDs
- On post_gist, append the new gist_id to the cell's list
- Rewrite list_gists_by_cell to read directly from the cell index instead of scanning all gists
- Maintain backward compatibility of the function signature
- Add cursor pagination within the cell's gist list
Technical Requirements
- Must maintain backward compatibility
- Must handle gists with author set (Option)
- Must use Soroban SDK's Vec efficiently
- Must not exceed Soroban contract size limits
Acceptance Criteria
- list_gists_by_cell returns same results as before for existing data
- Time complexity is O(k) where k = gists in cell (was O(n) where n = total gists)
- 1000 gists in different cells does not increase query cost for a single cell
- contract size stays under Soroban limits
- All existing tests pass
- New test: 1000 gists across 10 cells, verify cell query returns correct subset
File Inventory
Dependencies
Issue #1 (deduplicate contracts) should be done first to avoid wasted work.
Testing Strategy
- Unit test: post 100 gists, query cell, verify correct count
- Performance test: post 1000 gists, measure fee difference for cell query
- Edge cases: empty cell, cell with 1 gist, cell with max gists
Security Considerations
More efficient contract execution reduces attack surface for DoS via expensive queries.
Definition of Done
Problem Statement
The Soroban contract's
list_gists_by_cellfunction iterates over all gist IDs from the cursor to the total count, checking each gist's location_cell for a match. This is an O(n) scan that becomes prohibitively expensive (in terms of computation and fee) as the number of gists grows.Evidence
contracts/src/lib.rslines 66-85:for id in start..=total { ... if gist.location_cell == location_cell { ... } }Impact
Contract becomes unusable at scale. Transaction fees increase linearly with total gist count, not with the result set size. Users will be priced out of querying their local area.
Proposed Solution
Map<String, Vec<u64>>mapping location_cell to list of gist IDsTechnical Requirements
Acceptance Criteria
File Inventory
contracts/src/lib.rsDependencies
Issue #1 (deduplicate contracts) should be done first to avoid wasted work.
Testing Strategy
Security Considerations
More efficient contract execution reduces attack surface for DoS via expensive queries.
Definition of Done