1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-16 18:01:37 +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

@ -20,13 +20,9 @@ import (
func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) {
printer := locale.NewPrinter(request.UserLanguage(r))
sess := session.New(h.store, request.SessionID(r))
user, err := h.store.UserByID(request.UserID(r))
if err != nil {
html.ServerError(w, r, err)
return
}
userID := request.UserID(r)
integration, err := h.store.Integration(user.ID)
integration, err := h.store.Integration(userID)
if err != nil {
html.ServerError(w, r, err)
return
@ -35,7 +31,7 @@ func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) {
integrationForm := form.NewIntegrationForm(r)
integrationForm.Merge(integration)
if integration.FeverUsername != "" && h.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) {
if integration.FeverUsername != "" && h.store.HasDuplicateFeverUsername(userID, integration.FeverUsername) {
sess.NewFlashErrorMessage(printer.Print("error.duplicate_fever_username"))
html.Redirect(w, r, route.Path(h.router, "integrations"))
return
@ -49,7 +45,7 @@ func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) {
integration.FeverToken = ""
}
if integration.GoogleReaderUsername != "" && h.store.HasDuplicateGoogleReaderUsername(user.ID, integration.GoogleReaderUsername) {
if integration.GoogleReaderUsername != "" && h.store.HasDuplicateGoogleReaderUsername(userID, integration.GoogleReaderUsername) {
sess.NewFlashErrorMessage(printer.Print("error.duplicate_googlereader_username"))
html.Redirect(w, r, route.Path(h.router, "integrations"))
return