1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-30 19:22:11 +00:00

refactor(ui): standardize user variable naming and avoid a SQL query when only userID is used

- Use `user` everywhere, instead of sometimes `loggedUser`
- Delay the instantiation of some variables: no need to perform SQL queries for
  nothing.
- Remove a SQL query getting the whole user struct when only user.ID is used.
This commit is contained in:
Julien Voisin 2025-08-12 04:48:36 +02:00 committed by GitHub
parent 50c5996280
commit 5d9d0b2652
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 50 additions and 57 deletions

View file

@ -17,7 +17,7 @@ import (
)
func (h *handler) saveAPIKey(w http.ResponseWriter, r *http.Request) {
loggedUser, err := h.store.UserByID(request.UserID(r))
user, err := h.store.UserByID(request.UserID(r))
if err != nil {
html.ServerError(w, r, err)
return
@ -28,20 +28,20 @@ func (h *handler) saveAPIKey(w http.ResponseWriter, r *http.Request) {
Description: apiKeyForm.Description,
}
if validationErr := validator.ValidateAPIKeyCreation(h.store, loggedUser.ID, apiKeyCreationRequest); validationErr != nil {
if validationErr := validator.ValidateAPIKeyCreation(h.store, user.ID, apiKeyCreationRequest); validationErr != nil {
sess := session.New(h.store, request.SessionID(r))
view := view.New(h.tpl, r, sess)
view.Set("form", apiKeyForm)
view.Set("menu", "settings")
view.Set("user", loggedUser)
view.Set("countUnread", h.store.CountUnreadEntries(loggedUser.ID))
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(loggedUser.ID))
view.Set("errorMessage", validationErr.Translate(loggedUser.Language))
view.Set("user", user)
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
view.Set("errorMessage", validationErr.Translate(user.Language))
html.OK(w, r, view.Render("create_api_key"))
return
}
if _, err = h.store.CreateAPIKey(loggedUser.ID, apiKeyCreationRequest.Description); err != nil {
if _, err = h.store.CreateAPIKey(user.ID, apiKeyCreationRequest.Description); err != nil {
html.ServerError(w, r, err)
return
}