feat(19.3-04): purge the host site's page cache after FAQ saves and deletes
- FormAfterCreate/FormAfterUpdate run the locale check, then register a purge of kind faq through cooler.PurgeSiteCacheAfterCommit - new FormAfterDelete purges after the delete commits - purgeSiteCache helper takes the save transaction from cabana.TxFromContext and the purger from cooler.SiteCacheFromApp (site_cache.* keys) - TestFaqAdminPurgesSiteCache on Postgres
This commit is contained in:
10
README.md
10
README.md
@@ -19,6 +19,7 @@ It requires `golem15.translate`: every FAQ belongs to one translate locale throu
|
||||
- **Table.** `golem15_faq_faqs` keeps the PHP columns: id, name, slug, locale_id (NOT NULL), is_active (default false), description (text), content (text holding the JSON list of `{question, answer}` rows) and timestamps, with a non-unique index on (slug, locale_id). One gormigrate step creates it; AutoMigrate is not used.
|
||||
- **Model.** `models.FAQ` stores `content` as `lagoon.Jsonable` (`models.Content`) and belongs to the translate `Locale`. Fillable: name, slug, locale_id, is_active, description, content. A name, a slug and a locale are required.
|
||||
- **Admin.** A top-level FAQ item (icon `circle-question-mark`, order 500) with the side item FAQs, behind the permission `golem15.faq.faqs` (developer and publisher roles). The list shows id, name, slug, locale (by name, so rows of the same slug are told apart), active and the timestamps. The form has name, slug (preset from name), locale (relation, by name), is_active, description (rich editor) and content (a repeater, "Add question", each row a required question and a rich-editor answer). Rich text is sanitized on save by the framework's policy (`seaglass`), and the save answers with a notice naming each field it cleaned, such as `content.1.answer`.
|
||||
- **Site cache.** A FAQ create, update or delete in the admin asks the host site to drop its page caches once the save commits. See [Site cache](#site-cache).
|
||||
- **Public API.** `GET /_faq/api/v1/faqs/{slug}` serves an active FAQ in one locale. See [Usage](#usage).
|
||||
- **Import.** `faq:import-winter` copies a WinterCMS site's FAQs from the JSON Lines `scripts/winter-export.sql` produces. See [CLI commands](#cli-commands).
|
||||
- **Phrasebooks.** `lang/en/lang.yaml` and `lang/pl/lang.yaml` keep the PHP key names.
|
||||
@@ -67,6 +68,10 @@ cors:
|
||||
allowed_methods: ["GET"]
|
||||
```
|
||||
|
||||
### Site cache
|
||||
|
||||
A FAQ create, update or delete in the admin sends one purge request (`{"kind":"faq","slug":"<slug>"}`) to the host site after the save commits, through the framework's site-cache purger in `cooler`. Configure it once for the application with the framework keys `site_cache.purge_url` and `site_cache.purge_token` (`SUMMER_SITE_CACHE__PURGE_URL`, `SUMMER_SITE_CACHE__PURGE_TOKEN`); a site that extends `vue-faq-layer` 0.2.0 or later serves the matching route `POST /api/__site__/cache/purge` with `NUXT_SITE_CACHE_PURGE_TOKEN`. Without the keys nothing is sent. A save refused by the locale check sends nothing, and a failing or slow site never fails the save.
|
||||
|
||||
### Winter import
|
||||
|
||||
1. On the WinterCMS database, check the FAQ and translate locales table names named in the header of `scripts/winter-export.sql`, then run the read-only export:
|
||||
@@ -111,13 +116,14 @@ cors:
|
||||
|
||||
- Form: the PHP `span: none` and `cssClass: col-sm-4` layout becomes left and right spans in one flat form; the locale relation's `select: name` is `nameFrom: name`; a question is required in each content row.
|
||||
- List: a locale column is added, since several rows share a slug.
|
||||
- Saves: a committed save or delete purges the host site's page caches (the PHP plugin had no such hook; a site's cache held edits until its TTL ran out).
|
||||
- Saves: a FAQ without a locale is refused with 422 `errors.locale_required` (the locale relation is written after the model rules run, so the check follows the write and rolls it back).
|
||||
- API: the public JSON API replaces the PHP component; rich text is sanitized on save and again on output.
|
||||
- Timestamps are `TIMESTAMPTZ`.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- SummerCMS modules: backpack, bonfire, cabana, lagoon, pact, party, seaglass, surf, wire.
|
||||
- SummerCMS modules: backpack, bonfire, cabana, cooler, lagoon, pact, party, seaglass, surf, wire.
|
||||
- Compiled plugin: `golem15.translate` (`git.golem15.com/golem15/sm-translate-plugin`).
|
||||
- Third-party: `gorm.io/gorm`, `github.com/go-gormigrate/gormigrate/v2`. Test-only: `github.com/testcontainers/testcontainers-go` with its Postgres module, `github.com/jackc/pgx/v5`.
|
||||
|
||||
@@ -126,5 +132,5 @@ cors:
|
||||
```sh
|
||||
go vet ./...
|
||||
go test -short ./... # no Docker
|
||||
go test ./... # TestFaqAdminSmoke, TestFaqImportSmoke, TestFaqAPISmoke on a Postgres container
|
||||
go test ./... # TestFaqAdminSmoke, TestFaqImportSmoke, TestFaqAPISmoke, TestFaqAdminPurgesSiteCache on a Postgres container
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user