From 0968cc68a46adcb3dc0a0d4ebc1e3fbefef904c4 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 15 Nov 2026 01:41:01 +0800 Subject: [PATCH] gateway: the chat page's regexps compile when first used 6bdeedc6f compiled four package-level regexps in chatpage.go (chatFlash and the three Markdown ones) at launch. TestNoEagerPackageRegexps (package magpie) turned red on main, which the full suite at cd030691a found. They are lazyre.New now, as every other package-level regexp is. Run: on mica, go vet ./internal/gateway, go test -run TestNoEagerPackageRegexps . (red at cd030691a: chatpage.go:214, 453, 454, 455), and go test -run TestChatPage ./internal/gateway: ok. The full suite at cd030691a (-tags nogui -timeout 45m ./..., on mote) had one more red, TestEveryRouteHasACommandOrIsNamed (/api/providers/delete). It is not this change's, and it passes at origin/main 6f264030a, where settings_parity_test.go names the route. --- internal/gateway/chatpage.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/gateway/chatpage.go b/internal/gateway/chatpage.go index f88f4f64f..a385c2bf8 100644 --- a/internal/gateway/chatpage.go +++ b/internal/gateway/chatpage.go @@ -14,7 +14,6 @@ import ( "net/http" "net/url" "path" - "regexp" "slices" "strings" "sync" @@ -23,6 +22,7 @@ import ( "github.com/yetone/magpie/internal/access" "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/lazyre" "github.com/yetone/magpie/internal/provider" ) @@ -211,7 +211,7 @@ func (s *Server) chatPageModels(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, map[string]any{"object": "list", "data": data, "default": chatDefaultModel(shown)}) } -var chatFlash = regexp.MustCompile(`(?i)deepseek.*flash`) +var chatFlash = lazyre.New(`(?i)deepseek.*flash`) // chatDefaultModel is the model the page chats with when its picker chose // none: a DeepSeek flash model, as the page asks for, else the first. @@ -450,9 +450,9 @@ func (s *Server) chatTTS(w http.ResponseWriter, r *http.Request) { } var ( - mdLink = regexp.MustCompile(`!?\[([^\]]*)\]\([^)]*\)`) - mdMarks = regexp.MustCompile("(?m)^\\s{0,3}(#{1,6}\\s+|>\\s?|[-*+]\\s+|\\d+\\.\\s+)|[*_`~]+") - mdFences = regexp.MustCompile("(?s)```[^\n]*\n(.*?)```") + mdLink = lazyre.New(`!?\[([^\]]*)\]\([^)]*\)`) + mdMarks = lazyre.New("(?m)^\\s{0,3}(#{1,6}\\s+|>\\s?|[-*+]\\s+|\\d+\\.\\s+)|[*_`~]+") + mdFences = lazyre.New("(?s)```[^\n]*\n(.*?)```") ) // plainOfMarkdown is markdown as it is read aloud: no marks, a link's