From 06f3bf5c653a4333b16f6017af696ac96b1c39c9 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 4 Mar 2025 23:36:41 +0000 Subject: [PATCH] minor improvements to speed up page load and trims timeline to 50 events now --- appview/db/timeline.go | 5 +++++ appview/pages/pages.go | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/appview/db/timeline.go b/appview/db/timeline.go index d857b409..17d29652 100644 --- a/appview/db/timeline.go +++ b/appview/db/timeline.go @@ -40,6 +40,11 @@ func MakeTimeline(e Execer) ([]TimelineEvent, error) { }) } + // Limit the slice to 100 events + if len(events) > 50 { + events = events[:50] + } + sort.Slice(events, func(i, j int) bool { return events[i].EventAt.After(events[j].EventAt) }) diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 6a1b9087..239ea3e6 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -415,7 +415,17 @@ func (p *Pages) Static() http.Handler { if err != nil { log.Fatalf("no static dir found? that's crazy: %v", err) } - return http.StripPrefix("/static/", http.FileServer(http.FS(sub))) + // Custom handler to apply Cache-Control headers for font files + return Cache(http.StripPrefix("/static/", http.FileServer(http.FS(sub)))) +} + +func Cache(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if strings.HasPrefix(r.URL.Path, "/static/fonts") { + w.Header().Set("Cache-Control", "public, max-age=31536000, immutable") + } + h.ServeHTTP(w, r) + }) } func (p *Pages) Error500(w io.Writer) error { -- 2.54.0