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
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package indexer
|
|
|
|
import (
|
|
"github.com/zzet/gortex/internal/graph"
|
|
"github.com/zzet/gortex/internal/parser"
|
|
)
|
|
|
|
// persistConstValues writes a file's extracted constant literal values to
|
|
// the backend's constant_values sidecar (when it implements
|
|
// graph.ConstantValueWriter — the on-disk backend and the in-memory
|
|
// store both do). The resolver reads these to dereference a
|
|
// const-identifier Temporal dispatch name to its literal value across
|
|
// files.
|
|
//
|
|
// ExtractionResult.ConstValues carries pre-repo-prefix node ids / file
|
|
// paths (they are stamped at extraction time, before applyRepoPrefix
|
|
// rewrites the node ids). This helper replicates that same prefix
|
|
// transform so the persisted node_id matches the final graph node id the
|
|
// resolver looks up by, independent of when applyRepoPrefix ran. Each
|
|
// file's prior rows are deleted first so a reindex replaces them cleanly.
|
|
func (idx *Indexer) persistConstValues(result *parser.ExtractionResult) {
|
|
if result == nil || len(result.ConstValues) == 0 {
|
|
return
|
|
}
|
|
cw, ok := idx.graph.(graph.ConstantValueWriter)
|
|
if !ok {
|
|
return
|
|
}
|
|
prefix := ""
|
|
if idx.repoPrefix != "" {
|
|
prefix = idx.repoPrefix + "/"
|
|
}
|
|
rows := make([]graph.ConstantValueRow, 0, len(result.ConstValues))
|
|
fileSet := map[string]struct{}{}
|
|
for _, cv := range result.ConstValues {
|
|
rows = append(rows, graph.ConstantValueRow{
|
|
NodeID: prefix + cv.NodeID,
|
|
FilePath: prefix + cv.FilePath,
|
|
Value: cv.Value,
|
|
})
|
|
fileSet[prefix+cv.FilePath] = struct{}{}
|
|
}
|
|
files := make([]string, 0, len(fileSet))
|
|
for f := range fileSet {
|
|
files = append(files, f)
|
|
}
|
|
_ = cw.DeleteConstantValuesByFiles(idx.repoPrefix, files)
|
|
_ = cw.BulkSetConstantValues(idx.repoPrefix, rows)
|
|
}
|