perf(logging): optimize debug logging in PromptChatMemoryAdvisor (#3448)

- Enclosed debug logging statements within an isDebugEnabled() check
- Reduced unnecessary method calls and object creations when debug logging is disabled

Signed-off-by: Ahoo Wang <ahoowang@qq.com>
(cherry picked from commit e45b1b3f8d)
This commit is contained in:
Ahoo Wang
2025-06-06 17:19:45 +08:00
committed by Spring Builds
parent 0c43e24b66
commit 36903ebf52

View File

@@ -157,13 +157,18 @@ public final class PromptChatMemoryAdvisor implements BaseChatMemoryAdvisor {
if (!assistantMessages.isEmpty()) {
this.chatMemory.add(this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
assistantMessages);
logger.debug("[PromptChatMemoryAdvisor.after] Added ASSISTANT messages to memory for conversationId={}: {}",
this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
assistantMessages);
List<Message> memoryMessages = this.chatMemory
.get(this.getConversationId(chatClientResponse.context(), this.defaultConversationId));
logger.debug("[PromptChatMemoryAdvisor.after] Memory after ASSISTANT add for conversationId={}: {}",
this.getConversationId(chatClientResponse.context(), this.defaultConversationId), memoryMessages);
if (logger.isDebugEnabled()) {
logger.debug(
"[PromptChatMemoryAdvisor.after] Added ASSISTANT messages to memory for conversationId={}: {}",
this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
assistantMessages);
List<Message> memoryMessages = this.chatMemory
.get(this.getConversationId(chatClientResponse.context(), this.defaultConversationId));
logger.debug("[PromptChatMemoryAdvisor.after] Memory after ASSISTANT add for conversationId={}: {}",
this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
memoryMessages);
}
}
return chatClientResponse;
}