feat(19.3-04): purge the host site's page cache after menu and menu-entry saves, deletes and reorders
- menus controller gains the app accessor and FormAfterCreate/Update/Delete purging kind menu with the menu code - menu entries purge kind menu_entry with the entry id after the placement checks pass, on delete, and through pact.ReorderAfterSave with partition:<menu id> - purgeSiteCache helper on cabana.TxFromContext and cooler.SiteCacheFromApp - TestMenuAdminPurgesSiteCache on Postgres
This commit is contained in:
18
README.md
18
README.md
@@ -21,6 +21,7 @@ It requires no other plugin. Content types (blog posts, categories, pages) come
|
||||
- **Entry types.** The built-ins `url` (Link, `models.TypeURL`) and `divider` (Divider, `models.TypeDivider`), then every registry type with its owning plugin's label. The reference dropdown depends on the type through `signpost.ReferenceOptions`; built-ins take no reference. The admin save refuses an unknown type, a reference the type does not offer, a missing reference for a type that takes one, a URL outside the scheme allowlist and a target other than `_self`, `_blank` or empty.
|
||||
- **URL allowlist.** `classes.AllowedURL` accepts an empty URL, a path starting with `/`, a fragment starting with `#`, and `http:`, `https:`, `mailto:` and `tel:` URLs. Anything else (`javascript:`, `data:`, a URL with surrounding whitespace or control characters) is a 422 `errors.url_scheme` on save and a `null` URL in the API.
|
||||
- **Admin.** A top-level Menus item (icon `list`, order 510) with the side items Menus and Menu entries, both behind the permission `golem15.menu.manage_menu` (developer and publisher roles). Menus: name, code (preset from name), css_class, is_active. Menu entries: a list of every entry with a menu filter and the toolbar buttons reorder, create and delete; a form with menu, parent, type, title, url, reference, url_pattern, code, icon, css_class, target and is_published; a tree reorder page scoped to one menu (`config_reorder.yaml`, partition `menu_id`), which refuses a payload naming an entry of another menu with 409.
|
||||
- **Site cache.** A menu create, update or delete and a menu-entry create, update, delete or reorder in the admin ask the host site to drop its page caches once the save commits. See [Site cache](#site-cache).
|
||||
- **Public API.** `GET /_menu/api/v1/menus/{code}` serves an active menu with its published entries as a nested tree. See [Usage](#usage).
|
||||
- **Import.** `menu:import-winter` copies a WinterCMS site's menus and entries from the JSON Lines the export SQL files produce. See [CLI commands](#cli-commands).
|
||||
- **Phrasebooks.** `lang/en/lang.yaml` and `lang/pl/lang.yaml` keep the PHP key names.
|
||||
@@ -132,6 +133,18 @@ cors:
|
||||
allowed_methods: ["GET"]
|
||||
```
|
||||
|
||||
### Site cache
|
||||
|
||||
Every committed admin write of the menu screens sends one purge request to the host site, through the framework's site-cache purger in `cooler`:
|
||||
|
||||
| Save | Purge body |
|
||||
|------|------------|
|
||||
| Menu create, update, delete | `{"kind":"menu","slug":"<menu code>"}` |
|
||||
| Menu-entry create, update, delete | `{"kind":"menu_entry","slug":"<entry id>"}` |
|
||||
| Menu-entry reorder | `{"kind":"menu_entry","slug":"partition:<menu id>"}` (through cabana's `pact.ReorderAfterSave` hook) |
|
||||
|
||||
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-menu-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. The entry checks (menu, parent, type, URL, target) run first: a refused save sends nothing, and a failing or slow site never fails a save or a reorder.
|
||||
|
||||
### Winter import
|
||||
|
||||
1. On the WinterCMS database, check the table names and entry types named in the headers of `scripts/winter-export-menus.sql` and `scripts/winter-export-entries.sql`, then run both read-only exports:
|
||||
@@ -191,11 +204,12 @@ cors:
|
||||
- Type keys: PHP `link` is `url`; PHP `blog_categories` is the registry type `all-journal-categories` when a blog plugin registers it; `page` is not supported.
|
||||
- Saves: an entry with a parent always takes the parent's menu (PHP only when the menu was empty); the admin form refuses with 422 a parent from another menu than the one the form names (`errors.parent_menu`), and an entry moved to another menu takes its whole subtree along, so no descendant is left with a parent in another menu. An unknown type, a registry type that takes a reference saved without one (`errors.reference_required`; it would resolve to nothing and vanish from the public tree), a parent cycle, a disallowed URL or target and an entry without a menu are refused with 422; a menu code another menu uses is a 422.
|
||||
- API: the public JSON API replaces the PHP component and filters unpublished entries.
|
||||
- Site cache: a committed save, delete or reorder 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).
|
||||
- Timestamps are `TIMESTAMPTZ`.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- SummerCMS modules: backpack, bonfire, cabana, lagoon, pact, party, signpost, surf, wire.
|
||||
- SummerCMS modules: backpack, bonfire, cabana, cooler, lagoon, pact, party, signpost, surf, wire.
|
||||
- Compiled plugins: none.
|
||||
- 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`.
|
||||
|
||||
@@ -204,7 +218,7 @@ cors:
|
||||
```sh
|
||||
go vet ./...
|
||||
go test -short ./... # no Docker
|
||||
go test ./... # TestMenuAdminSmoke, TestMenuImportSmoke, TestMenuAPISmoke on a Postgres container
|
||||
go test ./... # TestMenuAdminSmoke, TestMenuImportSmoke, TestMenuAPISmoke, TestMenuAdminPurgesSiteCache on a Postgres container
|
||||
```
|
||||
|
||||
The smoke tests register a fake content plugin with the types `acme-page` (with references), `acme-list` (a list type) and `all-journal-categories`, so the plugin needs no content plugin to test.
|
||||
|
||||
Reference in New Issue
Block a user