feat(16.2-07): purge the host site cache after a category admin update

- classes.SiteCachePurger posts {kind, slug} with a bearer token to
  golem15.journal.site_cache.purge_url, 2 s timeout, logged, never fails a save
- PurgeSiteCacheAfterCommit runs it through lagoon.AfterCommit
- Boot builds and publishes the purger from the two config keys
- categories FormAfterUpdate registers the purge; Postgres test proves
  one authorized request after the commit
This commit is contained in:
2026-10-10 18:19:58 +02:00
parent 0efaa04be5
commit f3b223f131
5 changed files with 376 additions and 0 deletions

View File

@@ -2,11 +2,13 @@ package journal
import (
"embed"
"fmt"
"io/fs"
"net/http"
"strconv"
"time"
"git.golem15.com/golem15/sm-journal-plugin/classes"
"git.golem15.com/golem15/sm-journal-plugin/console"
"git.golem15.com/golem15/sm-journal-plugin/models"
"git.golem15.com/golem15/sm-journal-plugin/updates"
@@ -48,9 +50,33 @@ func (p *Plugin) Register(app *backpack.App) error {
func (p *Plugin) Boot(app *backpack.App) error {
p.app = app
if err := p.wireSiteCache(app); err != nil {
return err
}
return p.wireSearch(app)
}
// wireSiteCache builds the site cache purger from
// golem15.journal.site_cache.purge_url and purge_token and publishes it, so
// admin saves of posts and categories purge the host site's page caches.
// With neither key set nothing is published.
func (p *Plugin) wireSiteCache(app *backpack.App) error {
if app == nil || app.Config == nil {
return nil
}
purger, err := classes.NewSiteCachePurger(
app.Config.String(classes.SiteCachePurgeURLKey),
app.Config.String(classes.SiteCachePurgeTokenKey),
)
if err != nil {
return fmt.Errorf("golem15.journal: site cache: %w", err)
}
if purger == nil {
return nil
}
return app.Publish(purger)
}
func (p *Plugin) LangFS() fs.FS { return langFS }
func (p *Plugin) Migrations() []*gormigrate.Migration { return updates.All() }