🐛 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;
import cc.ryanc.halo.model.enums.PostStatus;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.PostService;
import freemarker.core.Environment;
@ -33,7 +34,7 @@ public class ArticleTagDirective implements TemplateDirectiveModel {
String method = map.get(METHOD_KEY).toString();
switch (method) {
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;
case "archives":
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 status status
* @param pageable pageable
* @return Page
*/
Page<Post> findPostByCategories(Category category, Pageable pageable);
Page<Post> findPostByCategoriesAndPostStatus(Category category, Integer status, Pageable pageable);
/**
*
*
* @param tag tag
* @param status status
* @param pageable pageable
* @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.service.CategoryService;
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 java.util.ArrayList;
@ -22,8 +20,6 @@ public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoryRepository categoryRepository;
private static final String CATEGORIES_CACHE_NAME = "categories";
/**
* /
*
@ -31,7 +27,6 @@ public class CategoryServiceImpl implements CategoryService {
* @return Category
*/
@Override
@CacheEvict(value = CATEGORIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Category saveByCategory(Category category) {
return categoryRepository.save(category);
}
@ -43,7 +38,6 @@ public class CategoryServiceImpl implements CategoryService {
* @return Category
*/
@Override
@CacheEvict(value = CATEGORIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
public Category removeByCateId(Long cateId) {
Optional<Category> category = this.findByCateId(cateId);
categoryRepository.delete(category.get());
@ -56,7 +50,6 @@ public class CategoryServiceImpl implements CategoryService {
* @return List
*/
@Override
@Cacheable(value = CATEGORIES_CACHE_NAME, key = "'category'")
public List<Category> findAllCategories() {
return categoryRepository.findAll();
}

View File

@ -176,6 +176,7 @@ public class PostServiceImpl implements PostService {
* @return List
*/
@Override
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_status_type_'+#status+'_'+#postType")
public List<Post> findPostByStatus(Integer status, String postType) {
return postRepository.findPostsByPostStatusAndPostType(status, postType);
}
@ -323,25 +324,28 @@ public class PostServiceImpl implements PostService {
*
*
* @param category category
* @param status status
* @param pageable pageable
* @return Page
*/
@Override
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_category_'+#category.cateId+'_'+#pageable.pageNumber")
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 status status
* @param pageable pageable
* @return Page
*/
@Override
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_tag_'+#tag.tagId+'_'+#pageable.pageNumber")
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"
timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU"/>
<cache
name="categories"
eternal="false"
maxElementsInMemory="100"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>