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.
This commit is contained in:
yetone
2026-11-15 01:41:12 +08:00
parent 57bc8eabf4
commit 0968cc68a4
+5 -5
View File
@@ -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