git-pr

created pr with 56.1 on 2025-03-27T20:16:09Z · by c8ef7d19
added 56.2 on 2025-03-27T20:17:48Z · by c8ef7d19
1: 0200c93 ! 1: a2710a3 refactor: custom index page
added 56.3 on 2025-03-28T14:48:26Z · by c8ef7d19
1: a2710a3 < -: ------- refactor: custom index page
-: ------- > 1: 7338b44 feat: allow config `desc` to add a description box to index page
added 56.4 on 2025-04-06T19:08:12Z · by c8ef7d19
1: 7338b44 < -: ------- feat: allow config `desc` to add a description box to index page
-: ------- > 1: 26daea4 feat(pgs): lru cache for object info and special files
-: ------- > 2: b004b64 chore(pgs): use http cache clear event to rm lru cache for special files
-: ------- > 3: 59f5618 refactor(pgs): store lru cache on web router
changed status to accepted on 2025-04-06T22:13:51Z · by c8ef7d19
cmds
checkout latest patchset:
ssh pr.pico.sh print 56 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print 56.[rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 56
set PR to open (enables RSS notifications):
ssh pr.pico.sh pr open 56
set PR to draft (stops RSS notifications):
ssh pr.pico.sh pr draft 56
+12 -6 pkg/apps/pgs/web.go #
......@@ -21,6 +21,8 @@ import (
2121 "github.com/darkweak/souin/plugins/souin/storages"
2222 "github.com/darkweak/storages/core"
2323 "github.com/gorilla/feeds"
24+ "github.com/hashicorp/golang-lru/v2/expirable"
25+ "github.com/picosh/pico/pkg/cache"
2426 "github.com/picosh/pico/pkg/db"
2527 sst "github.com/picosh/pico/pkg/pobj/storage"
2628 "github.com/picosh/pico/pkg/shared"
......@@ -93,14 +95,18 @@ func StartApiServer(cfg *PgsConfig) {
9395 type HasPerm = func(proj *db.Project) bool
9496
9597 type WebRouter struct {
96- Cfg *PgsConfig
97- RootRouter *http.ServeMux
98- UserRouter *http.ServeMux
98+ Cfg *PgsConfig
99+ RootRouter *http.ServeMux
100+ UserRouter *http.ServeMux
101+ RedirectsCache *expirable.LRU[string, []*RedirectRule]
102+ HeadersCache *expirable.LRU[string, []*HeaderRule]
99103 }
100104
101105 func NewWebRouter(cfg *PgsConfig) *WebRouter {
102106 router := &WebRouter{
103- Cfg: cfg,
107+ Cfg: cfg,
108+ RedirectsCache: expirable.NewLRU[string, []*RedirectRule](2048, nil, cache.CacheTimeout),
109+ HeadersCache: expirable.NewLRU[string, []*HeaderRule](2048, nil, cache.CacheTimeout),
104110 }
105111 router.initRouters()
106112 return router
......@@ -513,9 +519,9 @@ func (web *WebRouter) ServeAsset(fname string, opts *storage.ImgProcessOpts, fro
513519 go func() {
514520 for key := range web.Cfg.CacheClearingQueue {
515521 rKey := filepath.Join(key, "_redirects")
516- redirectsCache.Remove(rKey)
522+ web.RedirectsCache.Remove(rKey)
517523 hKey := filepath.Join(key, "_headers")
518- headersCache.Remove(hKey)
524+ web.HeadersCache.Remove(hKey)
519525 }
520526 }()
521527
+5 -11 pkg/apps/pgs/web_asset_handler.go #
......@@ -14,17 +14,10 @@ import (
1414 "net/http/httputil"
1515 _ "net/http/pprof"
1616
17- "github.com/hashicorp/golang-lru/v2/expirable"
18- "github.com/picosh/pico/pkg/cache"
1917 sst "github.com/picosh/pico/pkg/pobj/storage"
2018 "github.com/picosh/pico/pkg/shared/storage"
2119 )
2220
23-var (
24- redirectsCache = expirable.NewLRU[string, []*RedirectRule](2048, nil, cache.CacheTimeout)
25- headersCache = expirable.NewLRU[string, []*HeaderRule](2048, nil, cache.CacheTimeout)
26-)
27-
2821 type ApiAssetHandler struct {
2922 *WebRouter
3023 Logger *slog.Logger
......@@ -50,7 +43,8 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
5043 var redirects []*RedirectRule
5144
5245 redirectsCacheKey := filepath.Join(getSurrogateKey(h.UserID, h.ProjectDir), "_redirects")
53- if cachedRedirects, found := redirectsCache.Get(redirectsCacheKey); found {
46+ if cachedRedirects, found := h.RedirectsCache.Get(redirectsCacheKey); found {
47+ fmt.Println(cachedRedirects)
5448 redirects = cachedRedirects
5549 } else {
5650 redirectFp, redirectInfo, err := h.Cfg.Storage.GetObject(h.Bucket, filepath.Join(h.ProjectDir, "_redirects"))
......@@ -77,7 +71,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7771 }
7872 }
7973
80- redirectsCache.Add(redirectsCacheKey, redirects)
74+ h.RedirectsCache.Add(redirectsCacheKey, redirects)
8175 }
8276
8377 routes := calcRoutes(h.ProjectDir, h.Filepath, redirects)
......@@ -180,7 +174,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
180174 var headers []*HeaderRule
181175
182176 headersCacheKey := filepath.Join(getSurrogateKey(h.UserID, h.ProjectDir), "_headers")
183- if cachedHeaders, found := headersCache.Get(headersCacheKey); found {
177+ if cachedHeaders, found := h.HeadersCache.Get(headersCacheKey); found {
184178 headers = cachedHeaders
185179 } else {
186180 headersFp, headersInfo, err := h.Cfg.Storage.GetObject(h.Bucket, filepath.Join(h.ProjectDir, "_headers"))
......@@ -207,7 +201,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
207201 }
208202 }
209203
210- headersCache.Add(headersCacheKey, headers)
204+ h.HeadersCache.Add(headersCacheKey, headers)
211205 }
212206
213207 userHeaders := []*HeaderLine{}
+1 -1 pkg/apps/pgs/web_test.go #
......@@ -329,7 +329,7 @@ func TestApiBasic(t *testing.T) {
329329
330330 ct := responseRecorder.Header().Get("content-type")
331331 if ct != tc.contentType {
332- t.Errorf("Want status '%s', got '%s'", tc.contentType, ct)
332+ t.Errorf("Want content type '%s', got '%s'", tc.contentType, ct)
333333 }
334334
335335 body := strings.TrimSpace(responseRecorder.Body.String())
Back to top