refactor: simplify Node struct with public Tags/Relations fields

This commit is contained in:
2026-04-01 00:13:43 +02:00
parent 4020e5dab3
commit 77d3205e12
3 changed files with 40 additions and 103 deletions

View File

@@ -70,7 +70,7 @@ func (s *nodeServiceImpl) getAccessContext() (*accessContext, error) {
if err != nil {
return nil, err
}
rels := userNode.Relations()
rels := userNode.Relations
for _, nsID := range rels[string(models.RelHasWriteAccess)] {
ctx.writable[nsID] = true
ctx.readable[nsID] = true
@@ -83,7 +83,7 @@ func (s *nodeServiceImpl) getAccessContext() (*accessContext, error) {
// nodeNamespaceID returns the first in_namespace target of n, or "" if none.
func (s *nodeServiceImpl) nodeNamespaceID(n *models.Node) string {
ids := n.Relations()[string(models.RelInNamespace)]
ids := n.Relations[string(models.RelInNamespace)]
if len(ids) == 0 {
return ""
}
@@ -375,18 +375,17 @@ func (s *nodeServiceImpl) Update(id string, input UpdateInput) (*models.Node, er
// Compute new tag set using the model's AddTag/RemoveTag to preserve
// property-prefix replacement semantics.
tmp := models.NewNode()
for _, t := range current.Tags() {
for _, t := range current.Tags {
tmp.AddTag(t)
}
for _, t := range input.AddTags {
tmp.AddTag(t)
}
for _, t := range input.RemoveTags {
tmp.RemoveTag(t) //nolint: the error is only for _type:: removal, which is intentionally prevented
tmp.RemoveTag(t)
}
// Sync tags to store.
currentTags, newTags := current.Tags(), tmp.Tags()
currentTags, newTags := current.Tags, tmp.Tags
for _, t := range currentTags {
if !slices.Contains(newTags, t) {
if err := st.RemoveTag(id, t); err != nil {
@@ -409,7 +408,7 @@ func (s *nodeServiceImpl) Update(id string, input UpdateInput) (*models.Node, er
}
}
currentRels := current.Relations()
currentRels := current.Relations
for _, ri := range input.AddRels {
resolved, err := s.resolveRelTarget(st, ri)
if err != nil {
@@ -502,7 +501,7 @@ func (s *nodeServiceImpl) checkBlockers(id string) error {
func (s *nodeServiceImpl) syncMentions(st store.Store, id string, current *models.Node, newTitle, newContent string) error {
existingMentionIDs := make(map[string]bool)
for _, uid := range current.Relations()[string(models.RelMentions)] {
for _, uid := range current.Relations[string(models.RelMentions)] {
existingMentionIDs[uid] = true
}
mentionedUserIDs := make(map[string]bool)