Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Render request duration in the admin UI footer (cool!).

Kailash Nadhbca0261c0905
diff --git a/cmd/init.go b/cmd/init.go
index 3e9486cf..747d055d 100644
--- a/cmd/init.go
+++ b/cmd/init.go
@@ -962,6 +962,9 @@ func initHTTPServer(cfg *Config, urlCfg *UrlConfig, i *i18n.I18n, fs stuffbin.Fi
srv.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Set("app", app)
+
+ // Used for computing a request's finish time.
+ c.Set("start_time", time.Now())
return next(c)
}
})
diff --git a/cmd/public.go b/cmd/public.go
index 806cd6e0..9ca25da3 100644
--- a/cmd/public.go
+++ b/cmd/public.go
@@ -12,6 +12,7 @@ import (
"net/http"
"strconv"
"strings"
+ "time"
"github.com/knadh/listmonk/internal/captcha"
"github.com/knadh/listmonk/internal/i18n"
@@ -81,6 +82,7 @@ type adminTplData struct {
Lang string
ConfigJS serverConfig
I18nJS json.RawMessage
+ ReqDuration string
Data any
L *i18n.I18n
}
@@ -160,6 +162,12 @@ func (t *adminTplRenderer) Render(w io.Writer, name string, data any, c echo.Con
return err
}
+ // Compute request duration.
+ var reqDuration string
+ if start, ok := c.Get("start_time").(time.Time); ok {
+ reqDuration = time.Since(start).Round(time.Microsecond).String()
+ }
+
return t.templates.ExecuteTemplate(w, name, adminTplData{
SiteName: t.SiteName,
RootURL: t.RootURL,
@@ -169,6 +177,7 @@ func (t *adminTplRenderer) Render(w io.Writer, name string, data any, c echo.Con
Lang: t.Lang,
ConfigJS: configJS,
I18nJS: app.adminI18nJS,
+ ReqDuration: reqDuration,
Data: data,
L: app.i18n,
})
diff --git a/static/admin/views/base.html b/static/admin/views/base.html
index 878f487d..53161367 100644
--- a/static/admin/views/base.html
+++ b/static/admin/views/base.html
@@ -37,8 +37,6 @@
<a href="{{ URI "/admin" }}" class="logo"><img src="{{ URI "/admin/static/logo.svg" }}?v={{ .AssetVersion }}" alt="listmonk" /></a>
</div>
<div class="col-8 justify-end hstack">
- <button type="button" class="ghost small" data-cy="btn-refresh" title="{{ .L.T "globals.buttons.refresh" }}"
- onclick="document.location.reload()">{{ Icon "refresh-cw" }}</button>
{{ with .Data.Profile }}
<ot-dropdown>
<button popovertarget="user-menu" type="button" class="user-nav-button ghost small user-trigger">
@@ -63,7 +61,7 @@
{{ template "admin-sidebar" . }}
<footer id="footer">
- <a href="https://listmonk.app" class="unstyled text-light" target="_blank" rel="noopener noreferrer">{{ .ConfigJS.Version }}</a>
+ <span class="text-light text-8" title="Page render time">{{ .ReqDuration }}</span>
</footer>
</aside>