Commit 9670f6ec by lepdou

optimize find items interface

parent 26e377c6
......@@ -26,7 +26,6 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
......@@ -99,7 +98,7 @@ public class NamespaceUnlockAspect {
boolean isModified(Namespace namespace) {
Release release = releaseService.findLatestActiveRelease(namespace);
List<Item> items = itemService.findItems(namespace.getId());
List<Item> items = itemService.findItemsWithoutOrdered(namespace.getId());
if (release == null) {
return hasNormalItems(items);
......
......@@ -129,7 +129,7 @@ public class ItemController {
public List<ItemDTO> findItems(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName) {
return BeanUtils.batchTransform(ItemDTO.class, itemService.findItems(appId, clusterName, namespaceName));
return BeanUtils.batchTransform(ItemDTO.class, itemService.findItemsWithOrdered(appId, clusterName, namespaceName));
}
@RequestMapping(value = "/items/{itemId}", method = RequestMethod.GET)
......
......@@ -41,7 +41,7 @@ public class NamespaceUnlockAspectTest {
Namespace namespace = createNamespace(namespaceId);
when(releaseService.findLatestActiveRelease(namespace)).thenReturn(null);
when(itemService.findItems(namespaceId)).thenReturn(Collections.singletonList(createItem("", "")));
when(itemService.findItemsWithOrdered(namespaceId)).thenReturn(Collections.singletonList(createItem("", "")));
boolean isModified = namespaceUnlockAspect.isModified(namespace);
......@@ -57,7 +57,7 @@ public class NamespaceUnlockAspectTest {
List<Item> items = Arrays.asList(createItem("k1", "v1"), createItem("k2", "v2"));
when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
when(itemService.findItems(namespaceId)).thenReturn(items);
when(itemService.findItemsWithOrdered(namespaceId)).thenReturn(items);
when(namespaceService.findParentNamespace(namespace)).thenReturn(null);
boolean isModified = namespaceUnlockAspect.isModified(namespace);
......@@ -74,7 +74,7 @@ public class NamespaceUnlockAspectTest {
List<Item> items = Arrays.asList(createItem("k1", "v2"));
when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
when(itemService.findItems(namespaceId)).thenReturn(items);
when(itemService.findItemsWithOrdered(namespaceId)).thenReturn(items);
when(namespaceService.findParentNamespace(namespace)).thenReturn(null);
boolean isModified = namespaceUnlockAspect.isModified(namespace);
......@@ -91,7 +91,7 @@ public class NamespaceUnlockAspectTest {
List<Item> items = Arrays.asList(createItem("k2", "v2"));
when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
when(itemService.findItems(namespaceId)).thenReturn(items);
when(itemService.findItemsWithOrdered(namespaceId)).thenReturn(items);
when(namespaceService.findParentNamespace(namespace)).thenReturn(null);
boolean isModified = namespaceUnlockAspect.isModified(namespace);
......@@ -111,7 +111,7 @@ public class NamespaceUnlockAspectTest {
when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
when(itemService.findItems(childNamespaceId)).thenReturn(childItems);
when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
......@@ -131,7 +131,7 @@ public class NamespaceUnlockAspectTest {
when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
when(itemService.findItems(childNamespaceId)).thenReturn(childItems);
when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
......@@ -150,7 +150,7 @@ public class NamespaceUnlockAspectTest {
when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(null);
when(itemService.findItems(childNamespaceId)).thenReturn(childItems);
when(itemService.findItemsWithOrdered(childNamespaceId)).thenReturn(childItems);
when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
......
......@@ -15,6 +15,8 @@ public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
List<Item> findByNamespaceIdOrderByLineNumAsc(Long namespaceId);
List<Item> findByNamespaceId(Long namespaceId);
List<Item> findByNamespaceIdAndDataChangeLastModifiedTimeGreaterThan(Long namespaceId, Date date);
Item findFirst1ByNamespaceIdOrderByLineNumDesc(Long namespaceId);
......
......@@ -85,7 +85,24 @@ public class ItemService {
return item;
}
public List<Item> findItems(Long namespaceId) {
public List<Item> findItemsWithoutOrdered(Long namespaceId) {
List<Item> items = itemRepository.findByNamespaceId(namespaceId);
if (items == null) {
return Collections.emptyList();
}
return items;
}
public List<Item> findItemsWithoutOrdered(String appId, String clusterName, String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace != null) {
return findItemsWithoutOrdered(namespace.getId());
} else {
return Collections.emptyList();
}
}
public List<Item> findItemsWithOrdered(Long namespaceId) {
List<Item> items = itemRepository.findByNamespaceIdOrderByLineNumAsc(namespaceId);
if (items == null) {
return Collections.emptyList();
......@@ -93,10 +110,10 @@ public class ItemService {
return items;
}
public List<Item> findItems(String appId, String clusterName, String namespaceName) {
public List<Item> findItemsWithOrdered(String appId, String clusterName, String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace != null) {
return findItems(namespace.getId());
return findItemsWithOrdered(namespace.getId());
} else {
return Collections.emptyList();
}
......
......@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.biz.service;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.GrayReleaseRule;
......@@ -30,7 +29,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
......@@ -308,7 +306,7 @@ public class ReleaseService {
private Map<String, String> getNamespaceItems(Namespace namespace) {
List<Item> items = itemService.findItems(namespace.getId());
List<Item> items = itemService.findItemsWithoutOrdered(namespace.getId());
Map<String, String> configurations = new HashMap<String, String>();
for (Item item : items) {
if (StringUtils.isEmpty(item.getKey())) {
......
......@@ -63,7 +63,7 @@ public class NamespaceServiceIntegrationTest extends AbstractIntegrationTest {
namespaceService.deleteNamespace(namespace, testUser);
List<Item> items = itemService.findItems(testApp, testCluster, testPrivateNamespace);
List<Item> items = itemService.findItemsWithoutOrdered(testApp, testCluster, testPrivateNamespace);
List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace);
List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster);
......
......@@ -669,6 +669,11 @@
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils-core</artifactId>
</exclusion>
<!-- duplicated with spring-aop -->
<exclusion>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- end of eureka -->
......@@ -767,6 +772,11 @@
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils-core</artifactId>
</exclusion>
<!-- duplicated with spring-aop -->
<exclusion>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- end of eureka -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment