1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 13:30:26 +00:00

Categories: Remove hypha from all cata after deletion

This commit is contained in:
Timur Ismagilov 2022-10-29 16:01:06 +03:00
parent 474c69d6d2
commit b286c16ac2
2 changed files with 25 additions and 0 deletions

View File

@ -95,6 +95,29 @@ func removeHyphaFromCategory(hyphaName, catName string) {
go saveToDisk() go saveToDisk()
} }
// RemoveHyphaFromAllCategories removes the given hypha from all the categories.
func RemoveHyphaFromAllCategories(hyphaName string) {
cats := CategoriesWithHypha(hyphaName)
mutex.Lock()
defer mutex.Unlock()
for _, cat := range cats {
if node, ok := hyphaToCategories[hyphaName]; ok {
node.removeCategory(cat)
if len(node.categoryList) == 0 {
delete(hyphaToCategories, hyphaName)
}
}
if node, ok := categoryToHyphae[cat]; ok {
node.removeHypha(hyphaName)
if len(node.hyphaList) == 0 {
delete(categoryToHyphae, cat)
}
}
}
go saveToDisk()
}
// RenameHyphaInAllCategories finds all mentions of oldName and replaces them with newName. Pass canonical names. Make sure newName is not taken. If oldName is not in any category, RenameHyphaInAllCategories is a no-op. // RenameHyphaInAllCategories finds all mentions of oldName and replaces them with newName. Pass canonical names. Make sure newName is not taken. If oldName is not in any category, RenameHyphaInAllCategories is a no-op.
func RenameHyphaInAllCategories(oldName, newName string) { func RenameHyphaInAllCategories(oldName, newName string) {
mutex.Lock() mutex.Lock()

View File

@ -3,6 +3,7 @@ package shroom
import ( import (
"fmt" "fmt"
"github.com/bouncepaw/mycorrhiza/backlinks" "github.com/bouncepaw/mycorrhiza/backlinks"
"github.com/bouncepaw/mycorrhiza/categories"
"github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/history"
"github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/user" "github.com/bouncepaw/mycorrhiza/user"
@ -30,6 +31,7 @@ func Delete(u *user.User, h hyphae.ExistingHypha) error {
return hop.Errs[0] return hop.Errs[0]
} }
backlinks.UpdateBacklinksAfterDelete(h, originalText) backlinks.UpdateBacklinksAfterDelete(h, originalText)
categories.RemoveHyphaFromAllCategories(h.CanonicalName())
hyphae.DeleteHypha(h) hyphae.DeleteHypha(h)
return nil return nil
} }