Skip to content

Commit

Permalink
refactor: reply creation time
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Mar 13, 2024
1 parent 0f76008 commit e3d29ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public String getCommentName() {
public ListOptions toListOptions() {
var listOptions =
labelAndFieldSelectorToListOptions(getLabelSelector(), getFieldSelector());
listOptions.getFieldSelector()
var newFieldSelector = listOptions.getFieldSelector()
.andQuery(equal("spec.commentName", getCommentName()));
listOptions.setFieldSelector(newFieldSelector);
return listOptions;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package run.halo.app.core.extension.reconciler;

import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static run.halo.app.extension.ExtensionUtil.addFinalizers;

import java.util.Set;
Expand Down Expand Up @@ -45,6 +46,15 @@ public Result reconcile(Request request) {
eventPublisher.publishEvent(new ReplyCreatedEvent(this, reply));
}

if (reply.getSpec().getCreationTime() == null) {
reply.getSpec().setCreationTime(
defaultIfNull(reply.getSpec().getApprovedTime(),
reply.getMetadata().getCreationTimestamp()
)
);
}
client.update(reply);

replyNotificationSubscriptionHelper.subscribeNewReplyReasonForReply(reply);

eventPublisher.publishEvent(new ReplyChangedEvent(this, reply));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ public void onApplicationEvent(@NonNull ApplicationContextInitializedEvent event
indexSpecs.add(new IndexSpec()
.setName("spec.creationTime")
.setIndexFunc(simpleAttribute(Comment.class,
comment -> comment.getSpec().getCreationTime().toString())
comment -> defaultIfNull(comment.getSpec().getCreationTime(),
comment.getMetadata().getCreationTimestamp()).toString())
));
indexSpecs.add(new IndexSpec()
.setName("spec.approved")
Expand Down Expand Up @@ -286,7 +287,8 @@ public void onApplicationEvent(@NonNull ApplicationContextInitializedEvent event
indexSpecs.add(new IndexSpec()
.setName("spec.creationTime")
.setIndexFunc(simpleAttribute(Reply.class,
reply -> reply.getSpec().getCreationTime().toString())
reply -> defaultIfNull(reply.getSpec().getCreationTime(),
reply.getMetadata().getCreationTimestamp()).toString())
));
indexSpecs.add(new IndexSpec()
.setName("spec.commentName")
Expand Down

0 comments on commit e3d29ca

Please sign in to comment.