Optimize dashboard stats queries and creator group lookups#122
Merged
Conversation
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.
Summary
This PR reduces the cost of loading dashboard statistics by collapsing multi-pass aggregations into a single query path on the frontend, and by indexing on-chain group lookups by creator so dashboard-style reads no longer scan every group.
Previously, the overview widget computed totals with multiple client-side passes over the same dataset, and
get_groups_by_creatorloaded all groups before filtering. Both patterns scale poorly as group/task volume grows. This change preserves the same dashboard numbers and group listing behavior while cutting query work and round-trips.What changed
Frontend — single aggregated stats query
frontend/src/lib/dashboard-stats.tsGET /api/dashboard/statsCache-Control: no-storeconsistent with other API routesfrontend/src/constants/dashboard-groups.tsActiveGroupsWidgetto fetch from/api/dashboard/statsinstead of recomputing locallyContract — creator index for group lookups
DataKey::CreatorGroups(Address)storage indexcreate_autosharenow maintains the per-creator group ID listget_groups_by_creatornow:AllGroupsscan + filter (O(all groups)→O(creator’s groups))Acceptance criteria
70050($70.1K)53524500118Design notes
Why this approach
The repo does not use a traditional SQL ORM for the dashboard. Stats currently come from an in-memory/fixture dataset on the frontend, and group ownership lives on Soroban. Optimizations are therefore applied where the real query cost is:
Query reduction (frontend)
Contract lookup cost
get_groups_by_creatorTest plan
cd frontend && pnpm lint— 0 errorscd frontend && pnpm test— 31 passed (includes new dashboard stats tests)cd frontend && pnpm build— succeeds; route/api/dashboard/statspresentcd contract && cargo fmt --checkcd contract && cargo test --locked— 91 passedcd contract && cargo clippy --all-targets --all-features -- -D warnings/user/overviewand verify:GET /api/dashboard/statscallFollow-ups (out of scope)
closes #78