Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

53 lines
2.0 KiB
Go

package graph
// IsContentNode reports whether n is a CONTENT section node — a KindDoc
// chunk tagged data_class="content" (text / pdf / pptx / xlsx section
// bodies). Content bodies are indexed in the dedicated content store
// (ContentSearcher), never the symbol search, and are excluded from the
// code-oriented analysis passes — so this predicate is the single place
// every package agrees on what "content" means. Markdown prose (KindDoc
// without data_class=content) and data assets (data_class="data") are NOT
// content and keep their existing treatment.
func IsContentNode(n *Node) bool {
if n == nil || n.Kind != KindDoc || n.Meta == nil {
return false
}
dc, _ := n.Meta["data_class"].(string)
return dc == "content"
}
// NonContentNodeReader is an optional store capability: a cheap (SQL-level
// on the disk backend) enumeration of a repo's NON-content nodes, so the
// code-oriented passes (search-index build, embedding, language detection)
// never materialise a content-heavy repo's hundreds of thousands of content
// sections just to iterate past them.
type NonContentNodeReader interface {
GetRepoNonContentNodes(repoPrefix string) []*Node
}
// RepoCodeNodes returns repoPrefix's non-content nodes. It uses the store's
// NonContentNodeReader fast path when available (the disk backend filters in
// SQL, so 525k content sections never enter memory); otherwise it falls back
// to materialising the repo's nodes and dropping content in Go — fine for the
// in-memory store, which only backs small repos. An empty repoPrefix means
// "all repos".
func RepoCodeNodes(s Store, repoPrefix string) []*Node {
if r, ok := s.(NonContentNodeReader); ok {
return r.GetRepoNonContentNodes(repoPrefix)
}
var nodes []*Node
if repoPrefix != "" {
nodes = s.GetRepoNodes(repoPrefix)
}
if len(nodes) == 0 {
nodes = s.AllNodes()
}
out := make([]*Node, 0, len(nodes))
for _, n := range nodes {
if !IsContentNode(n) {
out = append(out, n)
}
}
return out
}