2020import org .springframework .data .domain .PageRequest ;
2121import org .springframework .data .domain .Pageable ;
2222import org .springframework .data .domain .Sort ;
23+ import org .springframework .scheduling .annotation .Async ;
2324import org .springframework .stereotype .Service ;
25+ import org .springframework .transaction .annotation .Transactional ;
2426
2527import java .util .ArrayList ;
2628import java .util .HashSet ;
3335 */
3436@ Service
3537@ Slf4j
38+ @ Transactional
3639public class PostService {
3740 public static final String CACHE_NAME = "cache.post" ;
3841 public static final String CACHE_NAME_ARCHIVE = CACHE_NAME + ".archive" ;
@@ -89,6 +92,7 @@ public Post getPublishedPostByPermalink(String permalink) {
8992 public Post createPost (Post post ) {
9093 if (post .getPostFormat () == PostFormat .MARKDOWN ) {
9194 post .setRenderedContent (Markdown .markdownToHtml (post .getContent ()));
95+ post .setRenderedSummary (Markdown .markdownToHtml (post .getSummary ()));
9296 }
9397
9498 return postRepository .save (post );
@@ -105,6 +109,7 @@ public Post createPost(Post post) {
105109 public Post updatePost (Post post ) {
106110 if (post .getPostFormat () == PostFormat .MARKDOWN ) {
107111 post .setRenderedContent (Markdown .markdownToHtml (post .getContent ()));
112+ post .setRenderedSummary (Markdown .markdownToHtml (post .getSummary ()));
108113 }
109114
110115 return postRepository .save (post );
@@ -217,4 +222,13 @@ public List<Object[]> countPostsByTags() {
217222
218223 return postRepository .countPostsByTags (PostStatus .PUBLISHED );
219224 }
225+
226+ @ Async
227+ public void incrementViews (Long postId ) {
228+ synchronized (this ) {
229+ Post post = postRepository .findOne (postId );
230+ post .setViews (post .getViews () + 1 );
231+ postRepository .save (post );
232+ }
233+ }
220234}
0 commit comments