diff --git a/CHANGES.md b/CHANGES.md index 31b051cb739..bd236472c33 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,5 +26,6 @@ Apollo 2.5.0 * [Feature: Support ordinary users to modify personal information](https://github.com/apolloconfig/apollo/pull/5511) * [Feature: Support exporting and importing configurations for specified applications and clusters](https://github.com/apolloconfig/apollo/pull/5517) * [doc: Add rust apollo client link](https://github.com/apolloconfig/apollo/pull/5514) +* [Perf: optimize namespace-related interface](https://github.com/apolloconfig/apollo/pull/5518) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/16?closed=1) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java index 30846b73fd7..164f7961eec 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java @@ -101,6 +101,11 @@ public List findPublicAppNamespaces() { return appNamespaceService.findPublicAppNamespaces(); } + @GetMapping("/appnamespaces/public/names") + public List findPublicAppNamespaceNames() { + return appNamespaceService.findPublicAppNamespaceNames(); + } + @GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces") public List findNamespaces(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName) { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java index 6edb245f114..79cf38d3396 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java @@ -32,6 +32,9 @@ public interface AppNamespaceRepository extends PagingAndSortingRepository findByIsPublicTrue(); + @Query("SELECT a.name FROM AppNamespace a WHERE a.isPublic = true AND a.isDeleted = false") + List findNamesByIsPublicTrue(); + List findByAppId(String appId); @Modifying diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java index 4eb36b750d7..b2d120f8ec2 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java @@ -70,6 +70,10 @@ public List findPublicAppNamespaces() { return appNamespaceRepository.findByIsPublicTrue(); } + public List findPublicAppNamespaceNames() { + return appNamespaceRepository.findNamesByIsPublicTrue(); + } + public AppNamespace findPublicAppNamespace(String namespaceName) { List appNamespaces = appNamespaceRepository.findByNameAndIsPublic(namespaceName, true); diff --git a/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js b/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js index be2f8165d8f..4d334246ea4 100644 --- a/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js +++ b/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js @@ -37,12 +37,12 @@ namespace_module.controller("LinkNamespaceController", $scope.pageSetting = setting; }); - NamespaceService.find_public_namespaces().then(function (result) { + NamespaceService.findPublicNamespaceNames().then(function (result) { var publicNamespaces = []; result.forEach(function (item) { var namespace = {}; - namespace.id = item.name; - namespace.text = item.name; + namespace.id = item; + namespace.text = item; publicNamespaces.push(namespace); }); $('#namespaces').select2({ diff --git a/apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js b/apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js index 48d42f1d192..cefc057fa2e 100644 --- a/apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js +++ b/apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js @@ -61,6 +61,11 @@ appService.service("NamespaceService", ['$resource', '$q', 'AppUtil', function ( method: 'GET', url: AppUtil.prefixPath() + '/apps/:appId/namespaces/:namespaceName/usage', isArray: true + }, + findPublicNamespaceNames: { + method: 'GET', + isArray: true, + url: AppUtil.prefixPath() + '/appnamespaces/public/names' } }); @@ -211,6 +216,16 @@ appService.service("NamespaceService", ['$resource', '$q', 'AppUtil', function ( return d.promise; } + function findPublicNamespaceNames() { + var d = $q.defer(); + namespace_source.findPublicNamespaceNames({}, function (result) { + d.resolve(result); + }, function (result) { + d.reject(result); + }); + return d.promise; + } + return { find_public_namespaces: find_public_namespaces, createNamespace: createNamespace, @@ -221,7 +236,8 @@ appService.service("NamespaceService", ['$resource', '$q', 'AppUtil', function ( loadAppNamespace: loadAppNamespace, deleteAppNamespace: deleteAppNamespace, getLinkedNamespaceUsage: getLinkedNamespaceUsage, - getNamespaceUsage: getNamespaceUsage + getNamespaceUsage: getNamespaceUsage, + findPublicNamespaceNames: findPublicNamespaceNames } }]);