2018-04-30 01:35:04 +02:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-10-08 03:42:43 +02:00
|
|
|
package ui // import "miniflux.app/ui"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/http/request"
|
|
|
|
"miniflux.app/http/response/html"
|
|
|
|
"miniflux.app/http/route"
|
|
|
|
"miniflux.app/model"
|
|
|
|
"miniflux.app/ui/session"
|
|
|
|
"miniflux.app/ui/view"
|
2020-12-19 00:08:17 +01:00
|
|
|
|
|
|
|
servertiming "github.com/mitchellh/go-server-timing"
|
2018-04-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
|
2020-12-19 00:08:17 +01:00
|
|
|
timing := servertiming.FromContext(r.Context())
|
|
|
|
prep := timing.NewMetric("pre_processing").Start()
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
2018-04-30 01:35:04 +02:00
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-19 00:08:17 +01:00
|
|
|
m := timing.NewMetric("sql_count_unread_entries").Start()
|
2018-04-30 01:35:04 +02:00
|
|
|
offset := request.QueryIntParam(r, "offset", 0)
|
2018-11-11 20:28:29 +01:00
|
|
|
builder := h.store.NewEntryQueryBuilder(user.ID)
|
2018-04-30 01:35:04 +02:00
|
|
|
builder.WithStatus(model.EntryStatusUnread)
|
2021-06-03 02:39:47 +02:00
|
|
|
builder.WithGloballyVisible()
|
2018-04-30 01:35:04 +02:00
|
|
|
countUnread, err := builder.CountEntries()
|
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
2020-12-19 00:08:17 +01:00
|
|
|
m.Stop()
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
if offset >= countUnread {
|
|
|
|
offset = 0
|
|
|
|
}
|
|
|
|
|
2020-12-19 00:08:17 +01:00
|
|
|
m = timing.NewMetric("sql_fetch_unread_entries").Start()
|
2018-11-11 20:28:29 +01:00
|
|
|
builder = h.store.NewEntryQueryBuilder(user.ID)
|
2018-04-30 01:35:04 +02:00
|
|
|
builder.WithStatus(model.EntryStatusUnread)
|
2021-05-14 13:51:51 +02:00
|
|
|
builder.WithOrder(user.EntryOrder)
|
2018-04-30 01:35:04 +02:00
|
|
|
builder.WithDirection(user.EntryDirection)
|
|
|
|
builder.WithOffset(offset)
|
2020-07-09 01:24:54 +02:00
|
|
|
builder.WithLimit(user.EntriesPerPage)
|
2021-06-03 02:39:47 +02:00
|
|
|
builder.WithGloballyVisible()
|
2018-04-30 01:35:04 +02:00
|
|
|
entries, err := builder.GetEntries()
|
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
2020-12-19 00:08:17 +01:00
|
|
|
m.Stop()
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
view.Set("entries", entries)
|
2020-07-09 01:24:54 +02:00
|
|
|
view.Set("pagination", getPagination(route.Path(h.router, "unread"), countUnread, offset, user.EntriesPerPage))
|
2018-04-30 01:35:04 +02:00
|
|
|
view.Set("menu", "unread")
|
|
|
|
view.Set("user", user)
|
2018-06-09 22:40:20 +02:00
|
|
|
view.Set("countUnread", countUnread)
|
2020-09-28 01:01:06 +02:00
|
|
|
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
2018-11-11 20:28:29 +01:00
|
|
|
view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID))
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2020-12-19 00:08:17 +01:00
|
|
|
prep.Stop()
|
|
|
|
|
|
|
|
m = timing.NewMetric("template_rendering").Start()
|
|
|
|
render := view.Render("unread_entries")
|
|
|
|
m.Stop()
|
|
|
|
|
|
|
|
html.OK(w, r, render)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|