캐릭터 챗봇 #338
| @@ -123,6 +123,31 @@ class ChatCharacterService( | |||||||
|         tags.distinct().forEach { addTagToCharacter(chatCharacter, it) } |         tags.distinct().forEach { addTagToCharacter(chatCharacter, it) } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 태그 매핑을 증분 업데이트(추가/삭제만)하여 불필요한 매핑 레코드 재생성을 방지 | ||||||
|  |      */ | ||||||
|  |     @Transactional | ||||||
|  |     fun updateTagsForCharacter(chatCharacter: ChatCharacter, tags: List<String>) { | ||||||
|  |         val desired = tags.distinct() | ||||||
|  |         // 현재 매핑된 태그 문자열 목록 | ||||||
|  |         val current = chatCharacter.tagMappings.map { it.tag.tag } | ||||||
|  |  | ||||||
|  |         // 추가가 필요한 태그 | ||||||
|  |         val toAdd = desired.filterNot { current.contains(it) } | ||||||
|  |         toAdd.forEach { addTagToCharacter(chatCharacter, it) } | ||||||
|  |  | ||||||
|  |         // 제거가 필요한 태그 매핑 | ||||||
|  |         if (chatCharacter.tagMappings.isNotEmpty()) { | ||||||
|  |             val iterator = chatCharacter.tagMappings.iterator() | ||||||
|  |             while (iterator.hasNext()) { | ||||||
|  |                 val mapping = iterator.next() | ||||||
|  |                 if (!desired.contains(mapping.tag.tag)) { | ||||||
|  |                     iterator.remove() // orphanRemoval=true 이므로 매핑 엔티티 삭제 처리 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 여러 가치관을 한번에 캐릭터에 연결 |      * 여러 가치관을 한번에 캐릭터에 연결 | ||||||
|      */ |      */ | ||||||
| @@ -412,8 +437,7 @@ class ChatCharacterService( | |||||||
|  |  | ||||||
|         // request에서 변경된 데이터만 업데이트 |         // request에서 변경된 데이터만 업데이트 | ||||||
|         if (request.tags != null) { |         if (request.tags != null) { | ||||||
|             chatCharacter.tagMappings.clear() |             updateTagsForCharacter(chatCharacter, request.tags) | ||||||
|             addTagsToCharacter(chatCharacter, request.tags) |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (request.values != null) { |         if (request.values != null) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user