Compare commits

...
1 Commits
Author SHA1 Message Date
schreifuchs 72bc974aa6 feat(gallery): preload images
release.yaml / publish (push) Successful in 3m4s
2026-09-10 14:02:05 +02:00
3 changed files with 24 additions and 1 deletions

No files matched your search

+5
View File
@@ -11,6 +11,7 @@ import (
"strings" "strings"
"time" "time"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/images"
"github.com/valkey-io/valkey-go" "github.com/valkey-io/valkey-go"
) )
@@ -22,6 +23,10 @@ type Image struct {
Height int Height int
} }
func (i Image) URL() string {
return images.URLFromUID(i.UID)
}
const ( const (
imagesKey = "gallery:images:list" imagesKey = "gallery:images:list"
hashKey = "gallery:images:hash" hashKey = "gallery:images:hash"
+5
View File
@@ -33,6 +33,11 @@ func UIDFromPath(path string) (uid string, err error) {
func URLFromPath(path string) (url string, err error) { func URLFromPath(path string) (url string, err error) {
uid, err := UIDFromPath(path) uid, err := UIDFromPath(path)
url = URLFromUID(uid)
return
}
func URLFromUID(uid string) (url string) {
url = "/images/" + uid url = "/images/" + uid
return return
} }
+14 -1
View File
@@ -1,12 +1,16 @@
package restgallery package restgallery
import ( import (
"fmt"
"log/slog" "log/slog"
"net/http" "net/http"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages" "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages"
) )
const preloadCount = 6
func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) { func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
imgs, err := h.srv.GetGallerySet(r.Context()) imgs, err := h.srv.GetGallerySet(r.Context())
if err != nil { if err != nil {
@@ -14,5 +18,14 @@ func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
h.r.Render(r.Context(), w, r, pages.GallerySet(imgs)) ctx := r.Context()
for i, image := range imgs.LG.Images {
if i > preloadCount {
break
}
slog.Info("preloading images", "img", image.UID)
ctx = templer.AppendHeader(ctx, fmt.Sprintf(`<link rel="preload" href="%s" as="image" />`, image.URL()))
}
h.r.Render(ctx, w, r, pages.GallerySet(imgs))
} }