1
0

chore(web): directly use new db session

(cherry picked from commit 499f66b7ae4d79e4b69c90caa618f25a18173925)
This commit is contained in:
kolaente 2024-08-29 16:31:46 +02:00
parent 459c8daed6
commit d885b43328
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
7 changed files with 15 additions and 13 deletions

View File

@ -125,7 +125,6 @@ func NewEcho() *echo.Echo {
}) })
handler.SetLoggingProvider(log.GetLogger()) handler.SetLoggingProvider(log.GetLogger())
handler.SetMaxItemsPerPage(config.ServiceMaxItemsPerPage.GetInt()) handler.SetMaxItemsPerPage(config.ServiceMaxItemsPerPage.GetInt())
handler.SetSessionFactory(db.NewSession)
return e return e
} }

View File

@ -19,7 +19,6 @@ package handler
import ( import (
"code.vikunja.io/api/pkg/web" "code.vikunja.io/api/pkg/web"
"github.com/op/go-logging" "github.com/op/go-logging"
"xorm.io/xorm"
) )
// Config contains the config for the web handler // Config contains the config for the web handler
@ -27,7 +26,6 @@ type Config struct {
AuthProvider *web.Auths AuthProvider *web.Auths
LoggingProvider *logging.Logger LoggingProvider *logging.Logger
MaxItemsPerPage int MaxItemsPerPage int
SessionFactory func() *xorm.Session
} }
var config *Config var config *Config
@ -50,8 +48,3 @@ func SetLoggingProvider(logger *logging.Logger) {
func SetMaxItemsPerPage(maxItemsPerPage int) { func SetMaxItemsPerPage(maxItemsPerPage int) {
config.MaxItemsPerPage = maxItemsPerPage config.MaxItemsPerPage = maxItemsPerPage
} }
// SetSessionFactory sets the session factory
func SetSessionFactory(sessionFactory func() *xorm.Session) {
config.SessionFactory = sessionFactory
}

View File

@ -21,6 +21,8 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"code.vikunja.io/api/pkg/db"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -51,7 +53,7 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
} }
// Create the db session // Create the db session
s := config.SessionFactory() s := db.NewSession()
defer func() { defer func() {
err = s.Close() err = s.Close()
if err != nil { if err != nil {

View File

@ -21,6 +21,8 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"code.vikunja.io/api/pkg/db"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -51,7 +53,7 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
} }
// Create the db session // Create the db session
s := config.SessionFactory() s := db.NewSession()
defer func() { defer func() {
err = s.Close() err = s.Close()
if err != nil { if err != nil {

View File

@ -23,6 +23,8 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"code.vikunja.io/api/pkg/db"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -84,7 +86,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
} }
// Create the db session // Create the db session
s := config.SessionFactory() s := db.NewSession()
defer func() { defer func() {
err = s.Close() err = s.Close()
if err != nil { if err != nil {

View File

@ -22,6 +22,8 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"code.vikunja.io/api/pkg/db"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -47,7 +49,7 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
} }
// Create the db session // Create the db session
s := config.SessionFactory() s := db.NewSession()
defer func() { defer func() {
err = s.Close() err = s.Close()
if err != nil { if err != nil {

View File

@ -21,6 +21,8 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"code.vikunja.io/api/pkg/db"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -52,7 +54,7 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
} }
// Create the db session // Create the db session
s := config.SessionFactory() s := db.NewSession()
defer func() { defer func() {
err = s.Close() err = s.Close()
if err != nil { if err != nil {