mirror of https://github.com/halo-dev/halo
parent
9b6314c040
commit
0b1e20216f
|
@ -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()));
|
||||
|
|
|
@ -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 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);
|
||||
|
||||
/**
|
||||
* 根据标签查询文章
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue