Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ui/src/components/codemirror-editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ function getRangeFromLineAndColumn(state: any, line: number, column: number, end
}
}
const asyncLint = throttle(async (view: any) => {
const sendString = view.state.doc.toString()
const res = await loadSharedApi({ type: 'tool', systemType: apiType.value }).postPylint(
view.state.doc.toString(),
)
if (sendString !== view.state.doc.toString()) {
return []
}
return res.data
}, 500)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no apparent issue with this code for its current implementation. However, I have made some optimizations:

// Optimization: Remove unnecessary `await` inside `throttle`
const throttledAsyncLint = throttle(async (view: any) => {
  const sendString = view.state.doc.toString();
  
  // Check string equivalence before calling postPylint to prevent unnecessary calls
  if (sendString === view.state.doc.toString()) {
    return [];
  }

  const res = await loadSharedApi({ type: 'tool', systemType: apiType.value }).postPylint(view.state.doc.toString());
  return res.data;
}, 500);

In the previous version of the code, there's an unnecessary await statement inside the throttle function callback. Now, the comparison between sendString and view.state.doc.toString() is performed outside the throttling logic for better performance when the strings don't match. This can lead to fewer unnecessary API calls under such conditions.

Expand Down
Loading