refactor: unify tags and edges into single rels table

This commit is contained in:
2026-04-01 12:50:45 +02:00
parent 27c72db042
commit 6288879468
9 changed files with 296 additions and 249 deletions

View File

@@ -5,8 +5,6 @@ import (
"strings"
)
var PropertyPrefixes = []string{"_type::", "_status::", "_prio::"}
type Node struct {
ID string `json:"id"`
Title string `json:"title"`
@@ -28,17 +26,16 @@ func (n *Node) AddTag(tag string) {
if tag == "" {
return
}
for _, prefix := range PropertyPrefixes {
if strings.HasPrefix(tag, prefix) {
var newTags []string
for _, t := range n.Tags {
if !strings.HasPrefix(t, prefix) {
newTags = append(newTags, t)
}
// If it's a property (name::value format), replace any existing tag with the same prefix.
if idx := strings.Index(tag, "::"); idx >= 0 {
prefix := tag[:idx+2]
var newTags []string
for _, t := range n.Tags {
if !strings.HasPrefix(t, prefix) {
newTags = append(newTags, t)
}
n.Tags = newTags
break
}
n.Tags = newTags
}
if !slices.Contains(n.Tags, tag) {
n.Tags = append(n.Tags, tag)
@@ -86,11 +83,10 @@ func (n *Node) RemoveRelation(relType RelType, target string) {
}
func (n *Node) GetProperty(k string) string {
prefix := "_" + k + "::"
for _, t := range n.Tags {
if strings.HasPrefix(t, "_") {
if p := strings.SplitN(t[1:], "::", 2); len(p) == 2 && p[0] == k {
return p[1]
}
if strings.HasPrefix(t, prefix) {
return strings.TrimPrefix(t, prefix)
}
}
return ""