Pagination deploy fix
This commit is contained in:
@@ -1439,6 +1439,7 @@ func (c *nodeBBClient) listNamespacePagesWithQuery(cid int, query string) ([]nod
|
||||
var out []nodeBBWikiPage
|
||||
after := ""
|
||||
seenCursors := map[string]struct{}{}
|
||||
seenPages := map[string]struct{}{}
|
||||
for {
|
||||
path := fmt.Sprintf("/api/v3/plugins/westgate-wiki/namespace/%d/pages?limit=80", cid)
|
||||
if query != "" {
|
||||
@@ -1452,14 +1453,34 @@ func (c *nodeBBClient) listNamespacePagesWithQuery(cid int, query string) ([]nod
|
||||
return nil, err
|
||||
}
|
||||
pages, next, hasMore := parseNodeBBWikiPageList(doc)
|
||||
out = append(out, pages...)
|
||||
newPages := 0
|
||||
for _, page := range pages {
|
||||
identity := nodeBBWikiPageIdentity(page)
|
||||
if identity == "" {
|
||||
out = append(out, page)
|
||||
newPages++
|
||||
continue
|
||||
}
|
||||
if _, ok := seenPages[identity]; ok {
|
||||
continue
|
||||
}
|
||||
seenPages[identity] = struct{}{}
|
||||
out = append(out, page)
|
||||
newPages++
|
||||
}
|
||||
if !hasMore || next == "" {
|
||||
return out, nil
|
||||
}
|
||||
if after != "" && next == after {
|
||||
if newPages == 0 {
|
||||
return out, nil
|
||||
}
|
||||
return nil, fmt.Errorf("NodeBB wiki namespace %d returned repeated pagination cursor %q", cid, next)
|
||||
}
|
||||
if _, ok := seenCursors[next]; ok {
|
||||
if newPages == 0 {
|
||||
return out, nil
|
||||
}
|
||||
return nil, fmt.Errorf("NodeBB wiki namespace %d returned repeated pagination cursor %q", cid, next)
|
||||
}
|
||||
seenCursors[next] = struct{}{}
|
||||
@@ -1467,6 +1488,18 @@ func (c *nodeBBClient) listNamespacePagesWithQuery(cid int, query string) ([]nod
|
||||
}
|
||||
}
|
||||
|
||||
func nodeBBWikiPageIdentity(page nodeBBWikiPage) string {
|
||||
if page.TID != 0 {
|
||||
return fmt.Sprintf("tid:%d", page.TID)
|
||||
}
|
||||
for _, value := range []string{page.WikiPath, page.CanonicalPath, page.Slug, page.Title} {
|
||||
if trimmed := strings.TrimSpace(value); trimmed != "" {
|
||||
return strings.ToLower(trimmed)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *nodeBBClient) createTopic(cid int, title, content, summary string) (nodeBBPost, error) {
|
||||
body := map[string]any{"cid": cid, "title": title, "content": content, "sourceContent": content}
|
||||
if summary != "" {
|
||||
|
||||
Reference in New Issue
Block a user