From 54c555d923cdd823c547f5ab41343eca7699b8fe Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Sun, 14 Jul 2024 12:28:32 +0200 Subject: [PATCH] Add limit to number of proposals returned --- examples/gno.land/p/demo/simpledao/propstore.gno | 9 +++++++++ examples/gno.land/p/demo/simpledao/propstore_test.gno | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/gno.land/p/demo/simpledao/propstore.gno b/examples/gno.land/p/demo/simpledao/propstore.gno index 127f64e75b7..99f584888fe 100644 --- a/examples/gno.land/p/demo/simpledao/propstore.gno +++ b/examples/gno.land/p/demo/simpledao/propstore.gno @@ -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 @@ -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 diff --git a/examples/gno.land/p/demo/simpledao/propstore_test.gno b/examples/gno.land/p/demo/simpledao/propstore_test.gno index 93b96c8a28b..efc8ebc1fe6 100644 --- a/examples/gno.land/p/demo/simpledao/propstore_test.gno +++ b/examples/gno.land/p/demo/simpledao/propstore_test.gno @@ -205,7 +205,7 @@ func TestPropStore_GetProposals(t *testing.T) { t.Parallel() var ( - numProposals = 50 + numProposals = 20 halfRange = numProposals / 2 p = NewPropStore()