mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-01 21:37:33 +08:00
Fix: The save interface is continuously called without any operation being performed on the agent page. (#17576)
This commit is contained in:
@@ -1153,7 +1153,8 @@ async def update_agent(agent_id, tenant_id):
|
||||
if not replica_ok:
|
||||
return get_data_error_result(message="agent saved, but replica sync failed.")
|
||||
|
||||
return get_json_result(data=True)
|
||||
_, updated_agent = UserCanvasService.get_by_id(agent_id)
|
||||
return get_json_result(data={"update_time": updated_agent.update_time})
|
||||
|
||||
|
||||
@manager.route("/agents/<agent_id>/reset", methods=["POST"]) # noqa: F821
|
||||
|
||||
@@ -341,7 +341,14 @@ func (h *AgentHandler) UpdateAgent(c *gin.Context) {
|
||||
common.ResponseWithCodeData(c, ec, nil, em)
|
||||
return
|
||||
}
|
||||
common.SuccessWithData(c, true, "success")
|
||||
canvas, err := h.agentService.GetAgent(c.Request.Context(), user.ID, canvasID)
|
||||
if err != nil || canvas == nil {
|
||||
common.SuccessWithData(c, map[string]interface{}{}, "success")
|
||||
return
|
||||
}
|
||||
common.SuccessWithData(c, map[string]interface{}{
|
||||
"update_time": canvas.UpdateTime,
|
||||
}, "success")
|
||||
}
|
||||
|
||||
// DeleteAgent removes the canvas and cascades to its versions.
|
||||
|
||||
@@ -590,7 +590,7 @@ def test_agents_crud_unit_branches(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
module.UserCanvasService,
|
||||
"get_by_id",
|
||||
lambda _id: (True, SimpleNamespace(title="agent-1", canvas_category=module.CanvasCategory.Agent)),
|
||||
lambda _id: (True, SimpleNamespace(title="agent-1", canvas_category=module.CanvasCategory.Agent, update_time=1234567890)),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
module.UserCanvasService,
|
||||
|
||||
@@ -444,7 +444,10 @@ export const useResetAgent = () => {
|
||||
return { data, loading, resetAgent: mutateAsync };
|
||||
};
|
||||
|
||||
export const useSetAgent = (showMessage: boolean = true) => {
|
||||
export const useSetAgent = (
|
||||
showMessage: boolean = true,
|
||||
skipInvalidation: boolean = false,
|
||||
) => {
|
||||
const { id } = useParams();
|
||||
const queryClient = useQueryClient();
|
||||
const {
|
||||
@@ -483,7 +486,7 @@ export const useSetAgent = (showMessage: boolean = true) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [AgentApiAction.FetchAgentListByPage],
|
||||
});
|
||||
if (agentId) {
|
||||
if (agentId && !skipInvalidation) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [AgentApiAction.FetchAgentDetail, agentId],
|
||||
});
|
||||
|
||||
@@ -14,9 +14,12 @@ import { useParams } from 'react-router';
|
||||
import useGraphStore from '../store';
|
||||
import { useBuildDslData } from './use-build-dsl';
|
||||
|
||||
export const useSaveGraph = (showMessage: boolean = true) => {
|
||||
export const useSaveGraph = (
|
||||
showMessage: boolean = true,
|
||||
skipInvalidation: boolean = false,
|
||||
) => {
|
||||
const { data } = useFetchAgent();
|
||||
const { setAgent, loading } = useSetAgent(showMessage);
|
||||
const { setAgent, loading } = useSetAgent(showMessage, skipInvalidation);
|
||||
const { id } = useParams();
|
||||
const { buildDslData } = useBuildDslData();
|
||||
|
||||
@@ -72,7 +75,7 @@ export const useWatchAgentChange = (chatDrawerVisible: boolean) => {
|
||||
const [time, setTime] = useState<string>();
|
||||
const nodes = useGraphStore((state) => state.nodes);
|
||||
const edges = useGraphStore((state) => state.edges);
|
||||
const { saveGraph } = useSaveGraph(false);
|
||||
const { saveGraph } = useSaveGraph(false, true);
|
||||
const { data: flowDetail } = useFetchAgent();
|
||||
|
||||
const setSaveTime = useCallback((updateTime: number) => {
|
||||
@@ -86,7 +89,7 @@ export const useWatchAgentChange = (chatDrawerVisible: boolean) => {
|
||||
const saveAgent = useCallback(async () => {
|
||||
if (!chatDrawerVisible) {
|
||||
const ret = await saveGraph();
|
||||
setSaveTime(ret.data.update_time);
|
||||
setSaveTime(ret.data.update_time ?? Date.now());
|
||||
}
|
||||
}, [chatDrawerVisible, saveGraph, setSaveTime]);
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ export function WikiLeftPanel({
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="ml-auto"
|
||||
disabled={loading}
|
||||
data-testid="wiki-clear-trigger"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user