mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-09 21:04:49 +08:00
Fix: prevent auto-incrementing memory name suffix when only permissions change (#16750)
This commit is contained in:
@@ -154,7 +154,9 @@ class MemoryService(CommonService):
|
||||
update_dict["memory_type"] = calculate_memory_type(update_dict["memory_type"])
|
||||
if "name" in update_dict:
|
||||
existing = cls.model.select().where((cls.model.id == memory_id) & (cls.model.tenant_id == tenant_id)).first()
|
||||
if not existing or existing.name != update_dict["name"]:
|
||||
if existing and existing.name == update_dict["name"]:
|
||||
update_dict.pop("name", None)
|
||||
else:
|
||||
update_dict["name"] = duplicate_name(cls.query, name=update_dict["name"], tenant_id=tenant_id)
|
||||
update_dict.update({"update_time": current_timestamp(), "update_date": get_format_time()})
|
||||
|
||||
|
||||
@@ -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