feat: sitemap index and per-type files from a slot table (tracer)

- contract package: Filter, Listing and their types (D-95)
- golem15_sitemap_urls slot table and the new settings columns
- Rebuild over signpost Records, stable slot assignment, rebuild job
- GET /sitemap.xml index and GET /_sitemap/files/{file} from the table
This commit is contained in:
Jakub Zych
2026-11-04 10:58:05 +01:00
parent 049f3ee270
commit 3359f1a196
17 changed files with 1564 additions and 577 deletions

View File

@@ -0,0 +1,52 @@
package updates
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
// createURLs creates golem15_sitemap_urls, the slot table the sitemap files
// are served from (D-30): one row per address (content type, record and
// locale; an additional address has type_key extra). grp is the file group,
// file_no the file within it (NULL until the address is numbered), so a
// rebuild keeps every listed address in its file. An address left out keeps
// its row with excluded_reason set and leaves a hole in its file.
var createURLs = []*gormigrate.Migration{
{
ID: "202610280001_create_golem15_sitemap_urls",
Migrate: func(tx *gorm.DB) error {
for _, stmt := range []string{
`CREATE TABLE golem15_sitemap_urls (
id BIGSERIAL PRIMARY KEY,
grp TEXT NOT NULL,
type_key TEXT NOT NULL,
record_id TEXT NOT NULL,
locale TEXT NOT NULL DEFAULT '',
url TEXT NOT NULL,
title TEXT NOT NULL DEFAULT '',
file_no INTEGER NULL,
first_seen TIMESTAMPTZ NOT NULL,
lastmod TIMESTAMPTZ NULL,
alternates JSONB NOT NULL DEFAULT '[]',
images JSONB NOT NULL DEFAULT '[]',
excluded_reason TEXT NOT NULL DEFAULT '',
updated_at TIMESTAMPTZ NOT NULL
)`,
`CREATE UNIQUE INDEX golem15_sitemap_urls_record_unique ON golem15_sitemap_urls (type_key, record_id, locale)`,
`CREATE INDEX golem15_sitemap_urls_file_index ON golem15_sitemap_urls (grp, file_no)`,
} {
if err := tx.Exec(stmt).Error; err != nil {
return err
}
}
return nil
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec(`DROP TABLE IF EXISTS golem15_sitemap_urls`).Error
},
},
}
func init() {
Register(createURLs...)
}

View File

@@ -0,0 +1,51 @@
package updates
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
// settingsColumns are the columns the per-type sitemap format adds to the
// settings singleton: the site address, the file size, the default locale,
// the additional addresses, the debounce time of the next rebuild
// (rebuild_pending_until), the file size the files are numbered for
// (numbered_size; a different file_size renumbers them), when the last
// rebuild finished (built_at) and when one was last requested from the
// admin (rebuild_requested_at). The Phase 17 columns stay in the table,
// unread.
var settingsColumns = []string{
"site_url TEXT NULL",
"file_size INTEGER NOT NULL DEFAULT 1000",
"default_locale TEXT NULL",
"extra_urls JSONB NULL DEFAULT '[]'",
"rebuild_pending_until TIMESTAMPTZ NULL",
"numbered_size INTEGER NULL",
"built_at TIMESTAMPTZ NULL",
"rebuild_requested_at TIMESTAMPTZ NULL",
}
var updateSettings = []*gormigrate.Migration{
{
ID: "202610280002_update_golem15_sitemap_settings",
Migrate: func(tx *gorm.DB) error {
for _, column := range settingsColumns {
if err := tx.Exec(`ALTER TABLE golem15_sitemap_settings ADD COLUMN ` + column).Error; err != nil {
return err
}
}
return tx.Exec(`INSERT INTO golem15_sitemap_settings (id) VALUES (1) ON CONFLICT (id) DO NOTHING`).Error
},
Rollback: func(tx *gorm.DB) error {
for _, name := range []string{"site_url", "file_size", "default_locale", "extra_urls", "rebuild_pending_until", "numbered_size", "built_at", "rebuild_requested_at"} {
if err := tx.Exec(`ALTER TABLE golem15_sitemap_settings DROP COLUMN IF EXISTS ` + name).Error; err != nil {
return err
}
}
return nil
},
},
}
func init() {
Register(updateSettings...)
}