Update index when updating resources.

This commit is contained in:
2025-09-08 21:24:08 +08:00
parent 5bf2544282
commit d64b1e78ef
3 changed files with 41 additions and 36 deletions

View File

@@ -73,6 +73,9 @@ func CreateResource(uid uint, params *ResourceParams) (uint, error) {
if err != nil {
log.Error("AddNewResourceActivity error: ", err)
}
if err := search.AddResourceToIndex(r); err != nil {
log.Error("AddResourceToIndex error: ", err)
}
return r.ID, nil
}
@@ -297,18 +300,7 @@ func SearchResource(query string, page int) ([]model.ResourceView, int, error) {
return nil, 0, err
}
if first {
for _, id := range res {
found := false
for _, id2 := range temp {
if id == id2 {
found = true
break
}
}
if !found {
temp = append(temp, id)
}
}
temp = utils.RemoveDuplicate(res)
first = false
} else {
temp1 := make([]uint, 0)
@@ -324,21 +316,7 @@ func SearchResource(query string, page int) ([]model.ResourceView, int, error) {
}
}
resources = append(resources, temp...)
// remove duplicates
temp = make([]uint, 0)
for _, id := range resources {
found := false
for _, id2 := range temp {
if id == id2 {
found = true
break
}
}
if !found {
temp = append(temp, id)
}
}
resources = utils.RemoveDuplicate(resources)
if start >= len(resources) {
return []model.ResourceView{}, 0, nil
@@ -393,6 +371,9 @@ func DeleteResource(uid, id uint) error {
if err != nil {
log.Error("Error updating cached tag list:", err)
}
if err := search.RemoveResourceFromIndex(id); err != nil {
log.Error("RemoveResourceFromIndex error: ", err)
}
return nil
}
@@ -474,6 +455,9 @@ func EditResource(uid, rid uint, params *ResourceParams) error {
if err != nil {
log.Error("AddUpdateResourceActivity error: ", err)
}
if err := search.AddResourceToIndex(r); err != nil {
log.Error("AddResourceToIndex error: ", err)
}
return nil
}