Logs
Patchsets
Range Diff ↕ rd-120
2: caace51 ! 1: 26daea4 feat(pgs): lru cache for object info and special files
1: 2cf56f0 ! 2: b004b64 chore(pgs): use http cache clear event to rm lru cache for special files
Range Diff ↕ rd-122
1: 26daea4 = 1: 26daea4 feat(pgs): lru cache for object info and special files
2: b004b64 = 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
Range Diff ↕ rd-123
1: 26daea4 = 1: 26daea4 feat(pgs): lru cache for object info and special files
2: b004b64 = 2: b004b64 chore(pgs): use http cache clear event to rm lru cache for special files
3: 59f5618 = 3: 59f5618 refactor(pgs): store lru cache on web router
-: ------- > 4: ee12290 refactor(pgs): update minio lru and remove object info cache
Range-diff rd-122
- title
- feat(pgs): lru cache for object info and special files
- description
-
Patch equal - old #1
26daea4- new #1
26daea4
- title
- chore(pgs): use http cache clear event to rm lru cache for special files
- description
-
Patch equal - old #2
b004b64- new #2
b004b64
- title
- refactor(pgs): store lru cache on web router
- description
-
Patch added - old #0
(none)- new #3
59f5618
1: 26daea4 = 1: 26daea4 feat(pgs): lru cache for object info and special files
2: b004b64 = 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
old
new
old:
pkg/apps/pgs/web.go
new:pkg/apps/pgs/web.go
"github.com/darkweak/souin/plugins/souin/storages" "github.com/darkweak/storages/core" "github.com/gorilla/feeds" + "github.com/hashicorp/golang-lru/v2/expirable" + "github.com/picosh/pico/pkg/cache" "github.com/picosh/pico/pkg/db" sst "github.com/picosh/pico/pkg/pobj/storage" "github.com/picosh/pico/pkg/shared" type HasPerm = func(proj *db.Project) bool type WebRouter struct { - Cfg *PgsConfig - RootRouter *http.ServeMux - UserRouter *http.ServeMux + Cfg *PgsConfig + RootRouter *http.ServeMux + UserRouter *http.ServeMux + RedirectsCache *expirable.LRU[string, []*RedirectRule] + HeadersCache *expirable.LRU[string, []*HeaderRule] } func NewWebRouter(cfg *PgsConfig) *WebRouter { router := &WebRouter{ - Cfg: cfg, + Cfg: cfg, + RedirectsCache: expirable.NewLRU[string, []*RedirectRule](2048, nil, cache.CacheTimeout), + HeadersCache: expirable.NewLRU[string, []*HeaderRule](2048, nil, cache.CacheTimeout), } router.initRouters() return router go func() { for key := range web.Cfg.CacheClearingQueue { rKey := filepath.Join(key, "_redirects") - redirectsCache.Remove(rKey) + web.RedirectsCache.Remove(rKey) hKey := filepath.Join(key, "_headers") - headersCache.Remove(hKey) + web.HeadersCache.Remove(hKey) } }()
old
new
old:
pkg/apps/pgs/web_asset_handler.go
new:pkg/apps/pgs/web_asset_handler.go
"net/http/httputil" _ "net/http/pprof" - "github.com/hashicorp/golang-lru/v2/expirable" - "github.com/picosh/pico/pkg/cache" sst "github.com/picosh/pico/pkg/pobj/storage" "github.com/picosh/pico/pkg/shared/storage" ) -var ( - redirectsCache = expirable.NewLRU[string, []*RedirectRule](2048, nil, cache.CacheTimeout) - headersCache = expirable.NewLRU[string, []*HeaderRule](2048, nil, cache.CacheTimeout) -) - type ApiAssetHandler struct { *WebRouter Logger *slog.Logger var redirects []*RedirectRule redirectsCacheKey := filepath.Join(getSurrogateKey(h.UserID, h.ProjectDir), "_redirects") - if cachedRedirects, found := redirectsCache.Get(redirectsCacheKey); found { + if cachedRedirects, found := h.RedirectsCache.Get(redirectsCacheKey); found { + fmt.Println(cachedRedirects) redirects = cachedRedirects } else { redirectFp, redirectInfo, err := h.Cfg.Storage.GetObject(h.Bucket, filepath.Join(h.ProjectDir, "_redirects")) } } - redirectsCache.Add(redirectsCacheKey, redirects) + h.RedirectsCache.Add(redirectsCacheKey, redirects) } routes := calcRoutes(h.ProjectDir, h.Filepath, redirects) var headers []*HeaderRule headersCacheKey := filepath.Join(getSurrogateKey(h.UserID, h.ProjectDir), "_headers") - if cachedHeaders, found := headersCache.Get(headersCacheKey); found { + if cachedHeaders, found := h.HeadersCache.Get(headersCacheKey); found { headers = cachedHeaders } else { headersFp, headersInfo, err := h.Cfg.Storage.GetObject(h.Bucket, filepath.Join(h.ProjectDir, "_headers")) } } - headersCache.Add(headersCacheKey, headers) + h.HeadersCache.Add(headersCacheKey, headers) } userHeaders := []*HeaderLine{}
old
new
old:
pkg/apps/pgs/web_test.go
new:pkg/apps/pgs/web_test.go
ct := responseRecorder.Header().Get("content-type") if ct != tc.contentType { - t.Errorf("Want status '%s', got '%s'", tc.contentType, ct) + t.Errorf("Want content type '%s', got '%s'", tc.contentType, ct) } body := strings.TrimSpace(responseRecorder.Body.String())