Copilot commented on code in PR #3174:
URL: https://github.com/apache/apisix-dashboard/pull/3174#discussion_r2278444031


##########
src/apis/ssls.ts:
##########
@@ -43,3 +43,22 @@ export const putSSLReq = (req: AxiosInstance, data: 
APISIXType['SSL']) => {
 
 export const postSSLReq = (req: AxiosInstance, data: SSLPostType) =>
   req.post<APISIXType['SSL'], APISIXType['RespSSLDetail']>(API_SSLS, data);
+
+export const deleteAllSSLs = async (req: AxiosInstance) => {
+  const { PAGE_SIZE_MIN, PAGE_SIZE_MAX } = await import('@/config/constant');

Review Comment:
   Using dynamic import inside a function that may be called multiple times is 
inefficient. Consider importing these constants at the module level or caching 
the import result.
   ```suggestion
     // PAGE_SIZE_MIN and PAGE_SIZE_MAX are now statically imported
   ```



##########
src/apis/ssls.ts:
##########
@@ -43,3 +43,22 @@ export const putSSLReq = (req: AxiosInstance, data: 
APISIXType['SSL']) => {
 
 export const postSSLReq = (req: AxiosInstance, data: SSLPostType) =>
   req.post<APISIXType['SSL'], APISIXType['RespSSLDetail']>(API_SSLS, data);
+
+export const deleteAllSSLs = async (req: AxiosInstance) => {
+  const { PAGE_SIZE_MIN, PAGE_SIZE_MAX } = await import('@/config/constant');
+  const totalRes = await getSSLListReq(req, {
+    page: 1,
+    page_size: PAGE_SIZE_MIN,
+  });
+  const total = totalRes.total;
+  if (total === 0) return;
+  for (let times = Math.ceil(total / PAGE_SIZE_MAX); times > 0; times--) {
+    const res = await getSSLListReq(req, {
+      page: 1,
+      page_size: PAGE_SIZE_MAX,
+    });
+    await Promise.all(
+      res.list.map((d) => req.delete(`${API_SSLS}/${d.value.id}`))
+    );
+  }

Review Comment:
   The loop continues to fetch page 1 repeatedly instead of tracking which 
records have been deleted. This could lead to inefficient deletion if records 
are not being removed in the expected order, potentially causing infinite loops 
or missing deletions.
   ```suggestion
     const { PAGE_SIZE_MAX } = await import('@/config/constant');
     const res = await getSSLListReq(req, {
       page: 1,
       page_size: PAGE_SIZE_MAX,
     });
     if (!res.list || res.list.length === 0) return;
     await Promise.all(
       res.list.map((d) => req.delete(`${API_SSLS}/${d.value.id}`))
     );
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to