back interdiff of round #2 and #1

appview: improve pagination.Page usage #519

closed
opened by ptr.pet targeting master from ptr.pet/core: pipeline-paginated
files
appview
db
issues
middleware
notifications
pages
templates
goodfirstissues
notifications
repo
issues
pagination
repo
state
ERROR
appview/db/issues.go

Failed to calculate interdiff for this file.

REBASED
appview/issues/issues.go

This patch was likely rebased, as context lines do not match.

REBASED
appview/issues/router.go

This patch was likely rebased, as context lines do not match.

ERROR
appview/middleware/middleware.go

Failed to calculate interdiff for this file.

ERROR
appview/pages/pages.go

Failed to calculate interdiff for this file.

ERROR
appview/pages/templates/repo/issues/issues.html

Failed to calculate interdiff for this file.

REBASED
appview/pagination/page.go

This patch was likely rebased, as context lines do not match.

REBASED
appview/repo/feed.go

This patch was likely rebased, as context lines do not match.

NEW
appview/db/notifications.go
···
limit ? offset ?
`, whereClause)
-
args = append(args, page.Limit, page.Offset)
+
args = append(args, page.Count, page.Count*page.No+1)
rows, err := e.QueryContext(context.Background(), query, args...)
if err != nil {
···
limit ? offset ?
`, whereClause)
-
args = append(args, page.Limit, page.Offset)
+
args = append(args, page.Count, page.Count*page.No+1)
rows, err := e.QueryContext(context.Background(), query, args...)
if err != nil {
···
// GetNotifications retrieves notifications with filters
func GetNotifications(e Execer, filters ...filter) ([]*models.Notification, error) {
-
return GetNotificationsPaginated(e, pagination.FirstPage(), filters...)
+
return GetNotificationsPaginated(e, pagination.Page{No: 0, Count: 30}, filters...)
}
func CountNotifications(e Execer, filters ...filter) (int64, error) {
NEW
appview/notifications/notifications.go
···
r.Group(func(r chi.Router) {
r.Use(middleware.AuthMiddleware(n.oauth))
-
r.With(middleware.Paginate).Get("/", n.notificationsPage)
+
r.With(middleware.Paginate(30)).Get("/", n.notificationsPage)
r.Post("/{id}/read", n.markRead)
r.Post("/read-all", n.markAllRead)
r.Delete("/{id}", n.deleteNotification)
···
page, ok := r.Context().Value("page").(pagination.Page)
if !ok {
log.Println("failed to get page")
-
page = pagination.FirstPage()
+
page = pagination.Page{No: 0, Count: 30}
}
total, err := db.CountNotifications(
···
n.pages.Error500(w)
return
}
+
paginate := pagination.NewFromPage(page, int(total))
notifications, err := db.GetNotificationsWithEntities(
n.db,
···
LoggedInUser: user,
Notifications: notifications,
UnreadCount: unreadCount,
-
Page: page,
+
Pagination: paginate,
Total: total,
})
}
NEW
appview/pages/templates/goodfirstissues/index.html
···
</div>
{{ end }}
-
{{ if or (gt .Page.Offset 0) (eq (len .RepoGroups) .Page.Limit) }}
+
{{ if or .Pagination.HasPreviousPage .Pagination.HasNextPage }}
<div class="flex justify-center mt-8">
<div class="flex gap-2">
-
{{ if gt .Page.Offset 0 }}
-
{{ $prev := .Page.Previous }}
+
{{ if .Pagination.HasPreviousPage }}
+
{{ $prev := .Pagination.PreviousPage }}
<a
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
hx-boost="true"
-
href="/goodfirstissues?offset={{ $prev.Offset }}&limit={{ $prev.Limit }}"
+
href="/goodfirstissues?page={{ add $prev.No 1 }}&count={{ $prev.Count }}"
>
{{ i "chevron-left" "w-4 h-4" }}
previous
···
<div></div>
{{ end }}
-
{{ if eq (len .RepoGroups) .Page.Limit }}
-
{{ $next := .Page.Next }}
+
{{ if .Pagination.HasNextPage }}
+
{{ $next := .Pagination.NextPage }}
<a
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
hx-boost="true"
-
href="/goodfirstissues?offset={{ $next.Offset }}&limit={{ $next.Limit }}"
+
href="/goodfirstissues?page={{ add $next.No 1 }}&count={{ $next.Count }}"
>
next
{{ i "chevron-right" "w-4 h-4" }}
NEW
appview/pages/templates/notifications/list.html
···
{{ define "pagination" }}
<div class="flex justify-end mt-4 gap-2">
-
{{ if gt .Page.Offset 0 }}
-
{{ $prev := .Page.Previous }}
+
{{ if .Pagination.HasPreviousPage }}
+
{{ $prev := .Pagination.PreviousPage }}
<a
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
hx-boost="true"
-
href = "/notifications?offset={{ $prev.Offset }}&limit={{ $prev.Limit }}"
+
href = "/notifications?page={{ add $prev.No 1 }}&count={{ $prev.Count }}"
>
{{ i "chevron-left" "w-4 h-4" }}
previous
···
<div></div>
{{ end }}
-
{{ $next := .Page.Next }}
-
{{ if lt $next.Offset .Total }}
-
{{ $next := .Page.Next }}
+
{{ if .Pagination.HasNextPage }}
+
{{ $next := .Pagination.NextPage }}
<a
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
hx-boost="true"
-
href = "/notifications?offset={{ $next.Offset }}&limit={{ $next.Limit }}"
+
href = "/notifications?page={{ add $next.No 1 }}&count={{ $next.Count }}"
>
next
{{ i "chevron-right" "w-4 h-4" }}
NEW
appview/state/gfi.go
···
page, ok := r.Context().Value("page").(pagination.Page)
if !ok {
-
page = pagination.FirstPage()
+
page = pagination.Page{No: 0, Count: 30}
}
goodFirstIssueLabel := fmt.Sprintf("at://%s/%s/%s", consts.TangledDid, tangled.LabelDefinitionNSID, "good-first-issue")
···
LoggedInUser: user,
RepoGroups: []*models.RepoGroup{},
LabelDefs: make(map[string]*models.LabelDefinition),
-
Page: page,
+
Pagination: pagination.NewFromPage(page, 0),
})
return
}
···
allIssues, err := db.GetIssuesPaginated(
s.db,
pagination.Page{
-
Limit: 500,
+
No: 0,
+
Count: 500,
},
db.FilterIn("repo_at", repoUris),
db.FilterEq("open", 1),
···
return
}
+
pagination := pagination.NewFromPage(page, len(allIssues))
+
var goodFirstIssues []models.Issue
for _, issue := range allIssues {
if issue.Labels.ContainsLabel(goodFirstIssueLabel) {
···
return sortedGroups[i].Repo.Name < sortedGroups[j].Repo.Name
})
-
groupStart := page.Offset
-
groupEnd := page.Offset + page.Limit
+
groupStart := page.Count * page.No
+
groupEnd := page.Count * (page.No + 1)
if groupStart > len(sortedGroups) {
groupStart = len(sortedGroups)
}
···
LoggedInUser: user,
RepoGroups: paginatedGroups,
LabelDefs: labelDefsMap,
-
Page: page,
+
Pagination: pagination,
GfiLabel: labelDefsMap[goodFirstIssueLabel],
})
}