🐛 bug修复

1.  后台分类管理会报懒加载的错误
2. 前台标签页面会显示回收站的文章
3. Material主题文章数会包含回收站和草稿
pull/21/head
ruibaby 2018-07-07 20:10:35 +08:00
parent 9b6314c040
commit 0b1e20216f
5 changed files with 15 additions and 25 deletions

View File

@ -1,5 +1,6 @@
package cc.ryanc.halo.model.tag; package cc.ryanc.halo.model.tag;
import cc.ryanc.halo.model.enums.PostStatus;
import cc.ryanc.halo.model.enums.PostType; import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import freemarker.core.Environment; import freemarker.core.Environment;
@ -33,7 +34,7 @@ public class ArticleTagDirective implements TemplateDirectiveModel {
String method = map.get(METHOD_KEY).toString(); String method = map.get(METHOD_KEY).toString();
switch (method) { switch (method) {
case "postsCount": case "postsCount":
environment.setVariable("postsCount", builder.build().wrap(postService.findAllPosts(PostType.POST_TYPE_POST.getDesc()).size())); environment.setVariable("postsCount", builder.build().wrap(postService.findPostByStatus(PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc()).size()));
break; break;
case "archives": case "archives":
environment.setVariable("archives", builder.build().wrap(postService.findPostGroupByYearAndMonth())); environment.setVariable("archives", builder.build().wrap(postService.findPostGroupByYearAndMonth()));

View File

@ -155,19 +155,21 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* *
* @param category category * @param category category
* @param status status
* @param pageable pageable * @param pageable pageable
* @return Page * @return Page
*/ */
Page<Post> findPostByCategories(Category category, Pageable pageable); Page<Post> findPostByCategoriesAndPostStatus(Category category, Integer status, Pageable pageable);
/** /**
* *
* *
* @param tag tag * @param tag tag
* @param status status
* @param pageable pageable * @param pageable pageable
* @return Page * @return Page
*/ */
Page<Post> findPostsByTags(Tag tag, Pageable pageable); Page<Post> findPostsByTagsAndPostStatus(Tag tag, Integer status, Pageable pageable);
/** /**
* *

View File

@ -4,8 +4,6 @@ import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.repository.CategoryRepository; import cc.ryanc.halo.repository.CategoryRepository;
import cc.ryanc.halo.service.CategoryService; import cc.ryanc.halo.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -22,8 +20,6 @@ public class CategoryServiceImpl implements CategoryService {
@Autowired @Autowired
private CategoryRepository categoryRepository; private CategoryRepository categoryRepository;
private static final String CATEGORIES_CACHE_NAME = "categories";
/** /**
* / * /
* *
@ -31,7 +27,6 @@ public class CategoryServiceImpl implements CategoryService {
* @return Category * @return Category
*/ */
@Override @Override
@CacheEvict(value = CATEGORIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Category saveByCategory(Category category) { public Category saveByCategory(Category category) {
return categoryRepository.save(category); return categoryRepository.save(category);
} }
@ -43,7 +38,6 @@ public class CategoryServiceImpl implements CategoryService {
* @return Category * @return Category
*/ */
@Override @Override
@CacheEvict(value = CATEGORIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Category removeByCateId(Long cateId) { public Category removeByCateId(Long cateId) {
Optional<Category> category = this.findByCateId(cateId); Optional<Category> category = this.findByCateId(cateId);
categoryRepository.delete(category.get()); categoryRepository.delete(category.get());
@ -56,7 +50,6 @@ public class CategoryServiceImpl implements CategoryService {
* @return List * @return List
*/ */
@Override @Override
@Cacheable(value = CATEGORIES_CACHE_NAME, key = "'category'")
public List<Category> findAllCategories() { public List<Category> findAllCategories() {
return categoryRepository.findAll(); return categoryRepository.findAll();
} }

View File

@ -176,6 +176,7 @@ public class PostServiceImpl implements PostService {
* @return List * @return List
*/ */
@Override @Override
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_status_type_'+#status+'_'+#postType")
public List<Post> findPostByStatus(Integer status, String postType) { public List<Post> findPostByStatus(Integer status, String postType) {
return postRepository.findPostsByPostStatusAndPostType(status, postType); return postRepository.findPostsByPostStatusAndPostType(status, postType);
} }
@ -323,25 +324,28 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param category category * @param category category
* @param status status
* @param pageable pageable * @param pageable pageable
* @return Page * @return Page
*/ */
@Override @Override
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_category_'+#category.cateId+'_'+#pageable.pageNumber")
public Page<Post> findPostByCategories(Category category, Pageable pageable) { public Page<Post> findPostByCategories(Category category, Pageable pageable) {
return postRepository.findPostByCategories(category,pageable); return postRepository.findPostByCategoriesAndPostStatus(category, PostStatus.PUBLISHED.getCode(), pageable);
} }
/** /**
* *
* *
* @param tag tag * @param tag tag
* @param status status
* @param pageable pageable * @param pageable pageable
* @return Page * @return Page
*/ */
@Override @Override
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_tag_'+#tag.tagId+'_'+#pageable.pageNumber") @CachePut(value = POSTS_CACHE_NAME, key = "'posts_tag_'+#tag.tagId+'_'+#pageable.pageNumber")
public Page<Post> findPostsByTags(Tag tag, Pageable pageable) { public Page<Post> findPostsByTags(Tag tag, Pageable pageable) {
return postRepository.findPostsByTags(tag, pageable); return postRepository.findPostsByTagsAndPostStatus(tag, PostStatus.PUBLISHED.getCode(), pageable);
} }
/** /**

View File

@ -80,14 +80,4 @@
timeToIdleSeconds="0" timeToIdleSeconds="0"
timeToLiveSeconds="300" timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU"/> memoryStoreEvictionPolicy="LRU"/>
<cache
name="categories"
eternal="false"
maxElementsInMemory="100"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU"/>
</ehcache> </ehcache>