Skip to content

Commit

Permalink
Add limit to number of proposals returned
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Jul 14, 2024
1 parent 209ee06 commit 54c555d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions examples/gno.land/p/demo/simpledao/propstore.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ var (
errMissingVote = errors.New("member has not voted")
)

// maxRequestProposals is the maximum number of
// paginated proposals that can be requested
const maxRequestProposals = 10

// proposal is the internal simpledao proposal implementation
type proposal struct {
author std.Address // initiator of the proposal
Expand Down Expand Up @@ -105,6 +109,11 @@ func (p *PropStore) GetProposals(offset, count uint64) []dao.Proposal {
return []dao.Proposal{}
}

// Limit the maximum number of returned proposals
if count > maxRequestProposals {
count = maxRequestProposals
}

var (
startIndex = offset
endIndex = startIndex + count
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/simpledao/propstore_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestPropStore_GetProposals(t *testing.T) {
t.Parallel()

var (
numProposals = 50
numProposals = 20
halfRange = numProposals / 2

p = NewPropStore()
Expand Down

0 comments on commit 54c555d

Please sign in to comment.