Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize pagination logic for queriers #4601

Closed
4 tasks
fedekunze opened this issue Jun 20, 2019 · 4 comments · Fixed by #4658
Closed
4 tasks

Generalize pagination logic for queriers #4601

fedekunze opened this issue Jun 20, 2019 · 4 comments · Fixed by #4658
Labels
good first issue Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.

Comments

@fedekunze
Copy link
Collaborator

fedekunze commented Jun 20, 2019

Summary

Create a generalized pagination function available for module Queriers.

Problem Definition

Currently, there's some code redundancy for pagination logic and not all the endpoints that return batched items use pagination. The goal of this issue is to create a general pagination function and use it all across the modules' REST endpoints. This functionality should live under /types/rest/rest.go.

Additionally, the implementer will have to update the swagger.yaml docs and add the query parameters for pagination and limit to each of the affected endpoints.

Proposal

Idea:

func PaginateResponse(lenItems, limit, page int) (start, end int) {
	if limit== 0 {
		limit = lenItems
	}

	start = (page - 1) * limit
	end = limit + start
	if end >= lenItems {
		end = lenItems
	}

	if start >= lenItems {
		// page is out of bounds
		return -1, -1
	}

	return
}

and on each of the queriers (see each module's querier.go):

...
start, end := PaginateResponse(len(items), params.Limit, params.Page)
if start == -1 && end == -1 {
     items = items{}
} else {
     items = items[start:end]
}
...

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@alexanderbez alexanderbez added Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. good first issue labels Jun 20, 2019
@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 200.0 DAI (200.0 USD @ $1.0/DAI) attached to it.

@gitcoinbot
Copy link

@rilwan11 Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@fedekunze fedekunze added the REST label Jun 28, 2019
@fedekunze
Copy link
Collaborator Author

updated description to match the goal of this issue

@gitcoinbot
Copy link

@rilwan11 Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants