mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-31 13:03:49 +08:00
Fix: prevent auto-incrementing memory name suffix when only permissions change (#16750)
This commit is contained in:
@@ -452,19 +452,26 @@ func (s *MemoryService) CreateMemory(tenantID string, req *CreateMemoryRequest)
|
||||
func (s *MemoryService) UpdateMemory(tenantID string, memoryID string, req *UpdateMemoryRequest) (*CreateMemoryResponse, error) {
|
||||
updateDict := make(map[string]interface{})
|
||||
|
||||
currentMemory, err := s.memoryDAO.GetByID(memoryID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("memory '%s' not found", memoryID)
|
||||
}
|
||||
|
||||
if req.Name != nil {
|
||||
memoryName := strings.TrimSpace(*req.Name)
|
||||
if err := common.ValidateName(memoryName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
memoryName, err := common.DuplicateName(func(name string, tid string) bool {
|
||||
existing, _ := s.memoryDAO.GetByNameAndTenant(name, tid)
|
||||
return len(existing) > 0
|
||||
}, memoryName, tenantID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if memoryName != strings.TrimSpace(currentMemory.Name) {
|
||||
memoryName, err := common.DuplicateName(func(name string, tid string) bool {
|
||||
existing, _ := s.memoryDAO.GetByNameAndTenant(name, tid)
|
||||
return len(existing) > 0
|
||||
}, memoryName, tenantID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updateDict["name"] = memoryName
|
||||
}
|
||||
updateDict["name"] = memoryName
|
||||
}
|
||||
|
||||
if req.Permissions != nil {
|
||||
@@ -552,11 +559,6 @@ func (s *MemoryService) UpdateMemory(tenantID string, memoryID string, req *Upda
|
||||
}
|
||||
}
|
||||
|
||||
currentMemory, err := s.memoryDAO.GetByID(memoryID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("memory '%s' not found", memoryID)
|
||||
}
|
||||
|
||||
if len(updateDict) == 0 {
|
||||
return formatRetDataFromMemory(currentMemory), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user