diff options
| author | 2025-09-06 20:17:22 +0700 | |
|---|---|---|
| committer | 2025-09-06 20:17:22 +0700 | |
| commit | 4161e051f4437a4ab68430a4e542b76b1f335c3a (patch) | |
| tree | 5c63fabb02fa9c55c9e7cf2c26c2a35a90806f35 /internal/router/api-v1-blog-search.go | |
| parent | d695dc09f44236be33fecc7a5ab9a326823170d9 (diff) | |
| parent | 13a66428533c5f870901343dd505bcb835015430 (diff) | |
| download | web-0.8.0.tar.gz web-0.8.0.zip | |
v0.8.0 (#7)v0.8.0
- feat: seamless single page application (not including map & index page
for now)
- feat: add pages cache
- feat: home page
- feat: change to mobile view on 1.1/1 aspect ratio (instead of 0.8/1)
- feat: always have page body in square aspect ratio
- feat: remove label in like button
- feat: stricter cors policy
- refactor: move lightlibrary css onto my bucket
- fix: use filename (not the whole path) for getting date in
lightgallery
- fix: don't put question mark in url if no params
Diffstat (limited to 'internal/router/api-v1-blog-search.go')
| -rw-r--r-- | internal/router/api-v1-blog-search.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/internal/router/api-v1-blog-search.go b/internal/router/api-v1-blog-search.go index e22fabe..41f2dec 100644 --- a/internal/router/api-v1-blog-search.go +++ b/internal/router/api-v1-blog-search.go @@ -1,6 +1,7 @@ package router import ( + "encoding/json" "fmt" "log/slog" "net/url" @@ -35,10 +36,17 @@ func Api_V1_BlogSearch(l map[string]*locale.LocaleConfig, langs []string, b2Clie slog.Warn("unable to parse a client timezone, defaulting to UTC", slog.String("error", err.Error()), slog.String("tz", tz)) } - pages, err := b2Client.Scan(lang + "/") - if err != nil { - c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8) - return c.Status(fiber.ErrInternalServerError.Code).SendString(fmt.Sprintf("failed to scan pages for '%s' lang: %v", lang, err)) + var pages []*b2.BlogPage + if pagesBytes, ok := PCache.Get("blog-search.pages-list"); pagesBytes != nil || ok { + json.Unmarshal(pagesBytes, &pages) + } else { + pages, err = b2Client.Scan(lang + "/") + if err != nil { + c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8) + return c.Status(fiber.ErrInternalServerError.Code).SendString(fmt.Sprintf("failed to scan pages for '%s' lang: %v", lang, err)) + } + pagesBytes, _ := json.Marshal(pages) + PCache.SetWithTTL("blog-search.pages-list", pagesBytes, int64(len(pagesBytes)), 5*time.Minute) } encodedQuery := c.Request().URI().QueryString() |