1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Add Server-Timing header to unread page

This commit is contained in:
Clément Joly 2020-12-18 23:08:17 +00:00 committed by GitHub
parent 2cf9bde1af
commit f88e93a0b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 153 additions and 2 deletions

View file

@ -13,9 +13,14 @@ import (
"miniflux.app/model"
"miniflux.app/ui/session"
"miniflux.app/ui/view"
servertiming "github.com/mitchellh/go-server-timing"
)
func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
timing := servertiming.FromContext(r.Context())
prep := timing.NewMetric("pre_processing").Start()
sess := session.New(h.store, request.SessionID(r))
view := view.New(h.tpl, r, sess)
@ -25,6 +30,7 @@ func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
return
}
m := timing.NewMetric("sql_count_unread_entries").Start()
offset := request.QueryIntParam(r, "offset", 0)
builder := h.store.NewEntryQueryBuilder(user.ID)
builder.WithStatus(model.EntryStatusUnread)
@ -33,11 +39,13 @@ func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
html.ServerError(w, r, err)
return
}
m.Stop()
if offset >= countUnread {
offset = 0
}
m = timing.NewMetric("sql_fetch_unread_entries").Start()
builder = h.store.NewEntryQueryBuilder(user.ID)
builder.WithStatus(model.EntryStatusUnread)
builder.WithOrder(model.DefaultSortingOrder)
@ -49,6 +57,7 @@ func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
html.ServerError(w, r, err)
return
}
m.Stop()
view.Set("entries", entries)
view.Set("pagination", getPagination(route.Path(h.router, "unread"), countUnread, offset, user.EntriesPerPage))
@ -58,5 +67,11 @@ func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID))
html.OK(w, r, view.Render("unread_entries"))
prep.Stop()
m = timing.NewMetric("template_rendering").Start()
render := view.Render("unread_entries")
m.Stop()
html.OK(w, r, render)
}