Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: optimize reply queries using index mechanisms (#5497)
#### What type of PR is this? /kind improvement /area core /milestone 2.14.x #### What this PR does / why we need it: 使用索引机制优化回复功能的查询以提高查询速度 #### Does this PR introduce a user-facing change? ```release-note 使用索引机制优化回复功能的查询以提高查询速度 ```
- Loading branch information
Showing
15 changed files
with
410 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 34 additions & 6 deletions
40
application/src/main/java/run/halo/app/content/comment/ReplyQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
package run.halo.app.content.comment; | ||
|
||
import static run.halo.app.extension.index.query.QueryFactory.equal; | ||
import static run.halo.app.extension.router.selector.SelectorUtil.labelAndFieldSelectorToListOptions; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.ServerWebInputException; | ||
import run.halo.app.core.extension.content.Reply; | ||
import run.halo.app.extension.router.IListRequest; | ||
import run.halo.app.extension.ListOptions; | ||
import run.halo.app.extension.PageRequest; | ||
import run.halo.app.extension.PageRequestImpl; | ||
import run.halo.app.extension.router.SortableRequest; | ||
|
||
/** | ||
* Query criteria for {@link Reply} list. | ||
* | ||
* @author guqing | ||
* @since 2.0.0 | ||
*/ | ||
public class ReplyQuery extends IListRequest.QueryListRequest { | ||
public class ReplyQuery extends SortableRequest { | ||
|
||
public ReplyQuery(MultiValueMap<String, String> queryParams) { | ||
super(queryParams); | ||
public ReplyQuery(ServerWebExchange exchange) { | ||
super(exchange); | ||
} | ||
|
||
@Schema(description = "Replies filtered by commentName.") | ||
public String getCommentName() { | ||
String commentName = queryParams.getFirst("commentName"); | ||
return StringUtils.isBlank(commentName) ? null : commentName; | ||
if (StringUtils.isBlank(commentName)) { | ||
throw new ServerWebInputException("The required parameter 'commentName' is missing."); | ||
} | ||
return commentName; | ||
} | ||
|
||
/** | ||
* Build list options from query criteria. | ||
*/ | ||
public ListOptions toListOptions() { | ||
var listOptions = | ||
labelAndFieldSelectorToListOptions(getLabelSelector(), getFieldSelector()); | ||
var newFieldSelector = listOptions.getFieldSelector() | ||
.andQuery(equal("spec.commentName", getCommentName())); | ||
listOptions.setFieldSelector(newFieldSelector); | ||
return listOptions; | ||
} | ||
|
||
public PageRequest toPageRequest() { | ||
var sort = getSort().and(Sort.by("spec.creationTime").ascending()); | ||
return PageRequestImpl.of(getPage(), getSize(), sort); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.