Skip to content

Commit

Permalink
Merge pull request #10 from ruksana2808/dev-4.8.18-get
Browse files Browse the repository at this point in the history
Issue with redis caching with search API because of newAddComment is resolved
  • Loading branch information
sharathkashyap authored Oct 18, 2024
2 parents 7551227 + 77ee0ac commit 9d1d5fe
Showing 1 changed file with 1 addition and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,7 @@ public ResponseDTO addNewCommentToTree(JsonNode payload) {
((ObjectNode) payload).put(Constants.COMMENT_ID, comment.getCommentId());
CommentTree commentTree = commentTreeService.updateCommentTree(payload);

Pageable pageable = PageRequest.of(defaultOffset, defaultLimit,
Sort.by(Sort.Direction.DESC, Constants.CREATED_DATE));
JsonNode childNodes = commentTree.getCommentTreeData().get(Constants.FIRST_LEVEL_NODES);
List<String> childNodeList = objectMapper.convertValue(childNodes, List.class);
List<Comment> comments = commentRepository.findByCommentIdIn(childNodeList, pageable)
.getContent();
// Fetch from db and add fetched comments into redis
List<Map<String, Object>> userList = new ArrayList<>();
userList = fetchUsersByCommentData(comments);
CommentsResoponseDTO commentsResoponseDTO = new CommentsResoponseDTO(commentTree,
comments, userList);
Optional.ofNullable(comments)
.ifPresent(commentsList -> commentsResoponseDTO.setCommentCount(childNodeList.size()));
Map<String, Object> resultMap = objectMapper.convertValue(commentsResoponseDTO, Map.class);
resultMap = objectMapper.convertValue(commentsResoponseDTO, Map.class);

deleteAndUpdateTheRedisKey(String.valueOf(payload.get(Constants.COMMENT_TREE_ID)), resultMap);
deleteRedisKey(String.valueOf(payload.get(Constants.COMMENT_TREE_ID)));
ResponseDTO responseDTO = new ResponseDTO(commentTree, comment);
return responseDTO;
}
Expand Down

0 comments on commit 9d1d5fe

Please sign in to comment.