2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package ui // import "miniflux.app/v2/internal/ui"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
2022-10-14 17:59:08 +02:00
|
|
|
"fmt"
|
2018-04-30 01:35:04 +02:00
|
|
|
"net/http"
|
2022-10-14 17:59:08 +02:00
|
|
|
"time"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2023-08-11 04:46:45 +02: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-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
|
2022-10-14 17:59:08 +02:00
|
|
|
beginPreProcessing := time.Now()
|
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
|
|
|
|
}
|
|
|
|
|
2022-10-14 17:59:08 +02:00
|
|
|
beginSqlCountUnreadEntries := time.Now()
|
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
|
|
|
|
}
|
2022-10-14 17:59:08 +02:00
|
|
|
finishSqlCountUnreadEntries := time.Now()
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
if offset >= countUnread {
|
|
|
|
offset = 0
|
|
|
|
}
|
|
|
|
|
2022-10-14 17:59:08 +02:00
|
|
|
beginSqlFetchUnreadEntries := time.Now()
|
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)
|
2023-06-19 23:00:10 +02:00
|
|
|
builder.WithSorting(user.EntryOrder, user.EntryDirection)
|
2018-04-30 01:35:04 +02:00
|
|
|
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
|
|
|
|
}
|
2022-10-14 17:59:08 +02:00
|
|
|
finishSqlFetchUnreadEntries := time.Now()
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2024-03-04 00:32:16 +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
|
|
|
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
|
|
|
|
2022-10-14 17:59:08 +02:00
|
|
|
finishPreProcessing := time.Now()
|
2020-12-19 00:08:17 +01:00
|
|
|
|
2022-10-14 17:59:08 +02:00
|
|
|
beginTemplateRendering := time.Now()
|
2020-12-19 00:08:17 +01:00
|
|
|
render := view.Render("unread_entries")
|
2022-10-14 17:59:08 +02: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-19 00:08:17 +01:00
|
|
|
|
|
|
|
html.OK(w, r, render)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|