Fix wiki deploy stale purge ordering

This commit is contained in:
2026-05-23 16:59:28 +02:00
parent 6d6367ad18
commit 1221156084
2 changed files with 224 additions and 2 deletions
+44 -2
View File
@@ -195,7 +195,7 @@ func DeployWikiWithOptions(p *project.Project, opts DeployWikiOptions, progress
if opts.Version != "" {
summary = fmt.Sprintf("%s (%s)", summary, opts.Version)
}
for _, plan := range plans {
for _, plan := range orderNodeBBDeployPlans(plans) {
switch plan.Action {
case "create":
created, err := client.createTopic(plan.Entry.CID, plan.Page.Title, plan.Content, summary)
@@ -241,6 +241,24 @@ func DeployWikiWithOptions(p *project.Project, opts DeployWikiOptions, progress
return result, nil
}
func orderNodeBBDeployPlans(plans []wikiDeployPlan) []wikiDeployPlan {
if len(plans) <= 1 {
return plans
}
ordered := make([]wikiDeployPlan, 0, len(plans))
for _, plan := range plans {
if plan.Action == "purge" {
ordered = append(ordered, plan)
}
}
for _, plan := range plans {
if plan.Action != "purge" {
ordered = append(ordered, plan)
}
}
return ordered
}
func loadWikiNamespaceDeclarations(p *project.Project) ([]wikiNamespaceDeclaration, error) {
cfg := p.EffectiveConfig().TopData.Wiki
path := filepath.Join(p.TopDataWikiSourceDir(), filepath.FromSlash(cfg.NamespacesFile))
@@ -687,7 +705,13 @@ func adoptExistingNodeBBPage(page wikiDeployPage, cid int, remotePagesByCID map[
}
func findExistingNodeBBPage(page wikiDeployPage, cid int, client *nodeBBClient) (wikiDeployManifestPage, bool, error) {
queries := []string{pageIDLeaf(page.PageID), page.Title, pageIDRemainder(page.PageID)}
queries := uniqueNodeBBPageSearchQueries(
pageIDLeaf(page.PageID),
page.Title,
canonicalWikiSegment(page.Title),
nodeBBPathLeaf(page.PublicPath),
pageIDRemainder(page.PageID),
)
for _, query := range queries {
query = strings.TrimSpace(query)
if query == "" {
@@ -708,6 +732,24 @@ func findExistingNodeBBPage(page wikiDeployPage, cid int, client *nodeBBClient)
return wikiDeployManifestPage{}, false, nil
}
func uniqueNodeBBPageSearchQueries(values ...string) []string {
queries := []string{}
seen := map[string]struct{}{}
for _, value := range values {
query := strings.TrimSpace(value)
if query == "" {
continue
}
key := strings.ToLower(query)
if _, ok := seen[key]; ok {
continue
}
seen[key] = struct{}{}
queries = append(queries, query)
}
return queries
}
func fetchNodeBBWikiPageMapping(page wikiDeployPage, cid int, remotePage nodeBBWikiPage, client *nodeBBClient) (wikiDeployManifestPage, bool, error) {
topic, err := client.getTopic(remotePage.TID)
if err != nil {