2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package ui // import "miniflux.app/v2/internal/ui"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
import (
|
2022-10-14 11:59:08 -04:00
|
|
|
"fmt"
|
2018-04-29 19:35:04 -04:00
|
|
|
"net/http"
|
2022-10-14 11:59:08 -04:00
|
|
|
"time"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/config"
|
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/html"
|
|
|
|
"miniflux.app/v2/internal/http/route"
|
|
|
|
"miniflux.app/v2/internal/model"
|
|
|
|
"miniflux.app/v2/internal/ui/session"
|
|
|
|
"miniflux.app/v2/internal/ui/view"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
|
2022-10-14 11:59:08 -04:00
|
|
|
beginPreProcessing := time.Now()
|
2020-12-18 18:08:17 -05:00
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
2018-04-29 19:35:04 -04:00
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-14 11:59:08 -04:00
|
|
|
beginSqlCountUnreadEntries := time.Now()
|
2018-04-29 19:35:04 -04:00
|
|
|
offset := request.QueryIntParam(r, "offset", 0)
|
2018-11-11 14:28:29 -05:00
|
|
|
builder := h.store.NewEntryQueryBuilder(user.ID)
|
2018-04-29 19:35:04 -04:00
|
|
|
builder.WithStatus(model.EntryStatusUnread)
|
2021-06-02 20:39:47 -04:00
|
|
|
builder.WithGloballyVisible()
|
2018-04-29 19:35:04 -04:00
|
|
|
countUnread, err := builder.CountEntries()
|
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
2022-10-14 11:59:08 -04:00
|
|
|
finishSqlCountUnreadEntries := time.Now()
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
if offset >= countUnread {
|
|
|
|
offset = 0
|
|
|
|
}
|
|
|
|
|
2022-10-14 11:59:08 -04:00
|
|
|
beginSqlFetchUnreadEntries := time.Now()
|
2018-11-11 14:28:29 -05:00
|
|
|
builder = h.store.NewEntryQueryBuilder(user.ID)
|
2018-04-29 19:35:04 -04:00
|
|
|
builder.WithStatus(model.EntryStatusUnread)
|
2023-06-19 17:00:10 -04:00
|
|
|
builder.WithSorting(user.EntryOrder, user.EntryDirection)
|
2018-04-29 19:35:04 -04:00
|
|
|
builder.WithOffset(offset)
|
2020-07-08 19:24:54 -04:00
|
|
|
builder.WithLimit(user.EntriesPerPage)
|
2021-06-02 20:39:47 -04:00
|
|
|
builder.WithGloballyVisible()
|
2018-04-29 19:35:04 -04:00
|
|
|
entries, err := builder.GetEntries()
|
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
2022-10-14 11:59:08 -04:00
|
|
|
finishSqlFetchUnreadEntries := time.Now()
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
view.Set("entries", entries)
|
2020-07-08 19:24:54 -04:00
|
|
|
view.Set("pagination", getPagination(route.Path(h.router, "unread"), countUnread, offset, user.EntriesPerPage))
|
2018-04-29 19:35:04 -04:00
|
|
|
view.Set("menu", "unread")
|
|
|
|
view.Set("user", user)
|
2018-06-09 16:40:20 -04:00
|
|
|
view.Set("countUnread", countUnread)
|
2020-09-27 19:01:06 -04:00
|
|
|
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
2018-11-11 14:28:29 -05:00
|
|
|
view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID))
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2022-10-14 11:59:08 -04:00
|
|
|
finishPreProcessing := time.Now()
|
2020-12-18 18:08:17 -05:00
|
|
|
|
2022-10-14 11:59:08 -04:00
|
|
|
beginTemplateRendering := time.Now()
|
2020-12-18 18:08:17 -05:00
|
|
|
render := view.Render("unread_entries")
|
2022-10-14 11:59:08 -04:00
|
|
|
finishTemplateRendering := time.Now()
|
|
|
|
|
|
|
|
if config.Opts.HasServerTimingHeader() {
|
|
|
|
w.Header().Set("Server-Timing", fmt.Sprintf("pre_processing;dur=%d,sql_count_unread_entries;dur=%d,sql_fetch_unread_entries;dur=%d,template_rendering;dur=%d",
|
|
|
|
finishPreProcessing.Sub(beginPreProcessing).Milliseconds(),
|
|
|
|
finishSqlCountUnreadEntries.Sub(beginSqlCountUnreadEntries).Milliseconds(),
|
|
|
|
finishSqlFetchUnreadEntries.Sub(beginSqlFetchUnreadEntries).Milliseconds(),
|
|
|
|
finishTemplateRendering.Sub(beginTemplateRendering).Milliseconds(),
|
|
|
|
))
|
|
|
|
}
|
2020-12-18 18:08:17 -05:00
|
|
|
|
|
|
|
html.OK(w, r, render)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|