appview/db: ignore pagination for non-paginated methods #713

merged
opened by boltless.me targeting master from push-ztsunkmpnsry

Each methods will check if page.limit is higher than 0, and only applies pagination when limit is higher than 0

Signed-off-by: Seongmin Lee git@boltless.me

Changed files
+15 -9
appview
+8 -5
appview/db/issues.go
···
pLower := FilterGte("row_num", page.Offset+1)
pUpper := FilterLte("row_num", page.Offset+page.Limit)
-
args = append(args, pLower.Arg()...)
-
args = append(args, pUpper.Arg()...)
-
pagination := " where " + pLower.Condition() + " and " + pUpper.Condition()
+
pageClause := ""
+
if page.Limit > 0 {
+
args = append(args, pLower.Arg()...)
+
args = append(args, pUpper.Arg()...)
+
pageClause = " where " + pLower.Condition() + " and " + pUpper.Condition()
+
}
query := fmt.Sprintf(
`
···
%s
`,
whereClause,
-
pagination,
+
pageClause,
)
rows, err := e.Query(query, args...)
···
}
func GetIssues(e Execer, filters ...filter) ([]models.Issue, error) {
-
return GetIssuesPaginated(e, pagination.FirstPage(), filters...)
+
return GetIssuesPaginated(e, pagination.Page{}, filters...)
}
func AddIssueComment(e Execer, c models.IssueComment) (int64, error) {
+7 -4
appview/db/notifications.go
···
whereClause += " AND " + condition
}
}
+
pageClause := ""
+
if page.Limit > 0 {
+
pageClause = " limit ? offset ? "
+
args = append(args, page.Limit, page.Offset)
+
}
query := fmt.Sprintf(`
select id, recipient_did, actor_did, type, entity_type, entity_id, read, created, repo_id, issue_id, pull_id
from notifications
%s
order by created desc
-
limit ? offset ?
-
`, whereClause)
-
-
args = append(args, page.Limit, page.Offset)
+
%s
+
`, whereClause, pageClause)
rows, err := e.QueryContext(context.Background(), query, args...)
if err != nil {