summaryrefslogtreecommitdiffstats
path: root/services/auth
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-08-28 10:43:25 +0100
committerGitHub <noreply@github.com>2022-08-28 10:43:25 +0100
commitbb0ff77e461ae080b1722701aea74010ff71e0ae (patch)
treed9550dc2f4342ca5babc4bf9191fa51aacdb922e /services/auth
parentc21d6511a8e0084644a53a3192f45443456b9a32 (diff)
downloadgitea-bb0ff77e461ae080b1722701aea74010ff71e0ae.tar.gz
gitea-bb0ff77e461ae080b1722701aea74010ff71e0ae.zip
Share HTML template renderers and create a watcher framework (#20218)
The recovery, API, Web and package frameworks all create their own HTML Renderers. This increases the memory requirements of Gitea unnecessarily with duplicate templates being kept in memory. Further the reloading framework in dev mode for these involves locking and recompiling all of the templates on each load. This will potentially hide concurrency issues and it is inefficient. This PR stores the templates renderer in the context and stores this context in the NormalRoutes, it then creates a fsnotify.Watcher framework to watch files. The watching framework is then extended to the mailer templates which were previously not being reloaded in dev. Then the locales are simplified to a similar structure. Fix #20210 Fix #20211 Fix #20217 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/auth')
-rw-r--r--services/auth/group.go5
-rw-r--r--services/auth/interface.go2
-rw-r--r--services/auth/sspi_windows.go12
3 files changed, 7 insertions, 12 deletions
diff --git a/services/auth/group.go b/services/auth/group.go
index 0f40e1a76c..bbafe64b49 100644
--- a/services/auth/group.go
+++ b/services/auth/group.go
@@ -5,6 +5,7 @@
package auth
import (
+ "context"
"net/http"
"reflect"
"strings"
@@ -51,14 +52,14 @@ func (b *Group) Name() string {
}
// Init does nothing as the Basic implementation does not need to allocate any resources
-func (b *Group) Init() error {
+func (b *Group) Init(ctx context.Context) error {
for _, method := range b.methods {
initializable, ok := method.(Initializable)
if !ok {
continue
}
- if err := initializable.Init(); err != nil {
+ if err := initializable.Init(ctx); err != nil {
return err
}
}
diff --git a/services/auth/interface.go b/services/auth/interface.go
index a05ece2078..ecc9ad2ca6 100644
--- a/services/auth/interface.go
+++ b/services/auth/interface.go
@@ -34,7 +34,7 @@ type Method interface {
type Initializable interface {
// Init should be called exactly once before using any of the other methods,
// in order to allow the plugin to allocate necessary resources
- Init() error
+ Init(ctx context.Context) error
}
// Named represents a named thing
diff --git a/services/auth/sspi_windows.go b/services/auth/sspi_windows.go
index 7e31378b6c..757d596c4c 100644
--- a/services/auth/sspi_windows.go
+++ b/services/auth/sspi_windows.go
@@ -5,6 +5,7 @@
package auth
import (
+ "context"
"errors"
"net/http"
"strings"
@@ -52,21 +53,14 @@ type SSPI struct {
}
// Init creates a new global websspi.Authenticator object
-func (s *SSPI) Init() error {
+func (s *SSPI) Init(ctx context.Context) error {
config := websspi.NewConfig()
var err error
sspiAuth, err = websspi.New(config)
if err != nil {
return err
}
- s.rnd = render.New(render.Options{
- Extensions: []string{".tmpl"},
- Directory: "templates",
- Funcs: templates.NewFuncMap(),
- Asset: templates.GetAsset,
- AssetNames: templates.GetAssetNames,
- IsDevelopment: !setting.IsProd,
- })
+ _, s.rnd = templates.HTMLRenderer(ctx)
return nil
}