Bläddra i källkod

数据库优化

xiongzhu 4 år sedan
förälder
incheckning
360c45b290

+ 3 - 3
src/main/java/com/izouma/nineth/domain/Collection.java

@@ -39,9 +39,9 @@ import java.util.List;
         @Index(columnList = "del"),
         @Index(columnList = "price"),
         @Index(columnList = "likes"),
-        @Index(columnList = "onShelf,del,type"),
-        @Index(columnList = "onShelf,del,source,type"),
-        @Index(columnList = "onShelf,del,source,salable,type"),
+        @Index(columnList = "onShelf,del"),
+        @Index(columnList = "onShelf,del,source"),
+        @Index(columnList = "onShelf,del,source,salable"),
 })
 @AllArgsConstructor
 @NoArgsConstructor

+ 20 - 20
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -87,8 +87,8 @@ public class CollectionService {
     @Cacheable(value = "collectionList", key = "#pageQuery.hashCode()")
     public PageWrapper<Collection> all(PageQuery pageQuery) {
         pageQuery.getQuery().put("del", false);
-        String type = MapUtils.getString(pageQuery.getQuery(), "type", "DEFAULT");
-        pageQuery.getQuery().remove("type");
+//        String type = MapUtils.getString(pageQuery.getQuery(), "type", "DEFAULT");
+//        pageQuery.getQuery().remove("type");
 
         Specification<Collection> specification = JpaUtils.toSpecification(pageQuery, Collection.class);
         PageRequest pageRequest = JpaUtils.toPageRequest(pageQuery);
@@ -97,24 +97,24 @@ public class CollectionService {
 //                    pageRequest.getSort().and(Sort.by("createdAt").descending()));
 //        }
 
-        specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
-            List<Predicate> and = new ArrayList<>();
-
-            if (StringUtils.isNotEmpty(type) && !"all".equalsIgnoreCase(type)) {
-                try {
-                    if (type.contains(",")) {
-                        and.add(root.get("type")
-                                .in(Arrays.stream(type.split(",")).map(s -> Enum.valueOf(CollectionType.class, s))
-                                        .collect(Collectors.toList())));
-                    } else {
-                        and.add(criteriaBuilder.equal(root.get("type"), Enum.valueOf(CollectionType.class, type)));
-                    }
-                } catch (Exception e) {
-
-                }
-            }
-            return criteriaBuilder.and(and.toArray(new Predicate[0]));
-        });
+//        specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
+//            List<Predicate> and = new ArrayList<>();
+//
+//            if (StringUtils.isNotEmpty(type) && !"all".equalsIgnoreCase(type)) {
+//                try {
+//                    if (type.contains(",")) {
+//                        and.add(root.get("type")
+//                                .in(Arrays.stream(type.split(",")).map(s -> Enum.valueOf(CollectionType.class, s))
+//                                        .collect(Collectors.toList())));
+//                    } else {
+//                        and.add(criteriaBuilder.equal(root.get("type"), Enum.valueOf(CollectionType.class, type)));
+//                    }
+//                } catch (Exception e) {
+//
+//                }
+//            }
+//            return criteriaBuilder.and(and.toArray(new Predicate[0]));
+//        });
         Page<Collection> page = collectionRepo.findAll(specification, pageRequest);
         return new PageWrapper<>(page.getContent(), page.getPageable().getPageNumber(),
                 page.getPageable().getPageSize(), page.getTotalElements());