apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
28.94k stars 10.19k forks source link

当一个项目存在大概500个namespace的情况下,页面打开到数据显示完成耗时很长,用户体检较差,这个目前有什么好的解决方案吗 #5065

Closed hezhaoye closed 4 months ago

hezhaoye commented 6 months ago

当一个项目存在大概500个namespace的情况下,页面打开到数据显示完成耗时很长,用户体检较差,这个目前有什么好的解决方案吗 通过浏览器的F12来看,耗时情况如图:

image

其中耗时最长的接口为portal模块中的NamespaceController.java中的接口

image
dosubot[bot] commented 6 months ago

🤖

你好 @hezhaoye,我是Dosu,一个可以帮助你解决问题,回答问题,甚至帮助你成为贡献者的机器人。在等待人类维护者回应的同时,我在这里为你提供帮助。

为了改善在项目有大约500个命名空间,页面加载和显示数据需要很长时间的用户体验,特别是在portal模块的NamespaceController.java接口中,你可以考虑实现分页和异步加载。

分页将允许你一次加载一定数量的命名空间,减少每个页面的加载时间。另一方面,异步加载将允许页面在数据可用时加载和显示数据,而不是等待所有数据准备就绪后再显示。

在提供的上下文中,NamespaceService.java中的findNamespaceBOs方法负责加载所有命名空间。这个方法可以修改以支持分页。以下是一个简单的例子,说明如何修改这个方法来实现分页:

public PageDTO<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName, int page, int size) {
    PageDTO<NamespaceDTO> namespaces = namespaceAPI.findNamespaceByCluster(appId, env, clusterName, page, size);
    if (namespaces == null || namespaces.getContent().size() == 0) {
      throw BadRequestException.namespaceNotExists();
    }

    List<NamespaceBO> namespaceBOs = namespaces.getContent().stream()
        .map(namespace -> transformNamespace2BO(env, namespace))
        .collect(Collectors.toList());

    return new PageDTO<>(namespaceBOs, namespaces.getTotal(), namespaces.getPageNumber(), namespaces.getPageSize());
}

在这个例子中,假设findNamespaceByCluster支持分页并返回一个PageDTO对象,该对象包含当前页面的命名空间列表,命名空间总数,当前页面号和页面大小。然后,findNamespaceBOs方法将每个NamespaceDTO转换为NamespaceBO,并返回一个新的PageDTO对象,该对象包含当前页面的NamespaceBO对象列表。

请注意,这只是一个简化的例子,实际的实现可能需要根据你的项目的具体情况进行额外的更改。例如,你可能需要修改NamespaceAPINamespaceController类以支持分页,并可能需要处理命名空间的排序和过滤。

来源:

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

nobodyiam commented 6 months ago

1261

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 4 months ago

This issue has been automatically closed because it has not had activity in the last 7 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.

0xc9e36 commented 4 months ago

我们内部做了多线程分批调用adminservice,100+ namespace大概只有不到1s就返回前端了