feat: entry generation job and cleanup on delete

This commit is contained in:
2026-10-27 10:48:02 +01:00
parent e8a6b9fc77
commit ab8905c429
10 changed files with 529 additions and 4 deletions

View File

@@ -4,13 +4,19 @@ import (
"context"
"errors"
"git.golem15.com/golem15/sm-seo-plugin/classes"
"git.golem15.com/golem15/sm-seo-plugin/models"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/diary"
"git.golem15.com/golem15/summercms/modules/lagoon"
"git.golem15.com/golem15/summercms/modules/pact"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
// log is the controllers' logger (component=seo).
var log = diary.For("seo")
// settingsAdminController edits the SEO settings singleton (D-104), linked
// from the SEO settings tile. Its per-content-type tabs are added by the
// plugin's own form extension on this controller.
@@ -65,6 +71,31 @@ func (c settingsAdminController) FormBeforeCreate(ctx context.Context, model any
return c.FormBeforeUpdate(ctx, model)
}
// FormAfterUpdate queues the entry generation job once the save commits,
// so the effective title and description cache follows new templates. A
// queue error is logged and never fails the save.
func (c settingsAdminController) FormAfterUpdate(ctx context.Context, _ any) error {
app := appOf(c.app)
svc, err := classes.NewService(app)
if err != nil {
return nil
}
tx, err := database(ctx, c.app)
if err != nil {
return nil
}
lagoon.AfterCommit(ctx, tx, func(ctx context.Context, _ *gorm.DB) {
db, ok := app.Lookup[*gorm.DB]()
if !ok || db == nil {
return
}
if _, err := svc.EnqueueGenerate(ctx, db.WithContext(ctx), ""); err != nil {
log.Warn("golem15.seo: queue entry generation", "error", err)
}
})
return nil
}
// stagingView is the view model of the staging partial.
type stagingView struct {
Staging bool
@@ -96,4 +127,5 @@ var (
_ pact.AdminPartialData = settingsAdminController{}
_ pact.FormBeforeCreate = settingsAdminController{}
_ pact.FormBeforeUpdate = settingsAdminController{}
_ pact.FormAfterUpdate = settingsAdminController{}
)