Skip to content

Commit

Permalink
refactor: empty value filtering for post query
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Jan 23, 2024
1 parent 73d03c9 commit 745d663
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder;
import static run.halo.app.extension.index.query.QueryFactory.and;
import static run.halo.app.extension.index.query.QueryFactory.equal;
import static run.halo.app.extension.index.query.QueryFactory.isNull;

import lombok.Data;
import org.springdoc.webflux.core.fn.SpringdocRouteBuilder;
Expand Down Expand Up @@ -75,7 +76,7 @@ Mono<ServerResponse> getStats(ServerRequest request) {
.flatMap(stats -> {
var listOptions = new ListOptions();
listOptions.setFieldSelector(FieldSelector.of(
and(equal("metadata.deletionTimestamp", null),
and(isNull("metadata.deletionTimestamp"),
equal("spec.deleted", "false")))
);
return client.listBy(Post.class, listOptions, PageRequestImpl.ofSize(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static run.halo.app.extension.index.query.QueryFactory.and;
import static run.halo.app.extension.index.query.QueryFactory.equal;
import static run.halo.app.extension.index.query.QueryFactory.isNull;

import java.time.Duration;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -146,7 +147,7 @@ private void populatePosts(Category category) {

var postListOptions = new ListOptions();
postListOptions.setFieldSelector(FieldSelector.of(
and(equal("metadata.deletionTimestamp", null),
and(isNull("metadata.deletionTimestamp"),
equal("spec.deleted", "false")))
);
var posts = client.listAll(Post.class, postListOptions, Sort.unsorted());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static run.halo.app.extension.index.query.QueryFactory.and;
import static run.halo.app.extension.index.query.QueryFactory.equal;
import static run.halo.app.extension.index.query.QueryFactory.isNull;

import lombok.AllArgsConstructor;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -52,7 +53,7 @@ Mono<Integer> postCount() {
.eq(Post.PUBLISHED_LABEL, "true")
.build());
var fieldQuery = and(
equal("metadata.deletionTimestamp", null),
isNull("metadata.deletionTimestamp"),
equal("spec.deleted", "false")
);
listOptions.setFieldSelector(FieldSelector.of(fieldQuery));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static run.halo.app.extension.index.query.QueryFactory.and;
import static run.halo.app.extension.index.query.QueryFactory.equal;
import static run.halo.app.extension.index.query.QueryFactory.isNull;
import static run.halo.app.extension.index.query.QueryFactory.or;

import java.security.Principal;
Expand Down Expand Up @@ -48,7 +49,7 @@ public Mono<ListOptions> getListOptions() {
.eq(Post.PUBLISHED_LABEL, "true").build());

var fieldQuery = and(
equal("metadata.deletionTimestamp", null),
isNull("metadata.deletionTimestamp"),
equal("spec.deleted", "false")
);
var visibleQuery = equal("spec.visible", Post.VisibleEnum.PUBLIC.name());
Expand Down

0 comments on commit 745d663

Please sign in to comment.