Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/main/java/run/halo/app/event/post/PostDeletedEvent.java

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/java/run/halo/app/event/post/PostEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package run.halo.app.event.post;

public interface PostEvent {

String getName();

}
5 changes: 3 additions & 2 deletions src/main/java/run/halo/app/event/post/PostPublishedEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.springframework.context.ApplicationEvent;

public class PostPublishedEvent extends ApplicationEvent {
public class PostPublishedEvent extends ApplicationEvent implements PostEvent {

private final String postName;

Expand All @@ -11,7 +11,8 @@ public PostPublishedEvent(Object source, String postName) {
this.postName = postName;
}

public String getPostName() {
@Override
public String getName() {
return postName;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/run/halo/app/event/post/PostRecycledEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.springframework.context.ApplicationEvent;

public class PostRecycledEvent extends ApplicationEvent {
public class PostRecycledEvent extends ApplicationEvent implements PostEvent {

private final String postName;

Expand All @@ -11,7 +11,7 @@ public PostRecycledEvent(Object source, String postName) {
this.postName = postName;
}

public String getPostName() {
public String getName() {
return postName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.springframework.context.ApplicationEvent;

public class PostUnpublishedEvent extends ApplicationEvent {
public class PostUnpublishedEvent extends ApplicationEvent implements PostEvent {

private final String postName;

Expand All @@ -11,7 +11,8 @@ public PostUnpublishedEvent(Object source, String postName) {
this.postName = postName;
}

public String getPostName() {
@Override
public String getName() {
return postName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.stream.IntStream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StopWatch;
import run.halo.app.extension.controller.RequestQueue.DelayedEntry;
Expand All @@ -32,6 +33,7 @@ public class DefaultController<R> implements Controller {

private final ExecutorService executor;

@Nullable
private final Synchronizer<R> synchronizer;

private final Duration minDelay;
Expand Down Expand Up @@ -144,7 +146,9 @@ public String getName() {
@Override
public void run() {
log.info("Controller worker {} started", this.name);
synchronizer.start();
if (synchronizer != null) {
synchronizer.start();
}
while (!isDisposed() && !Thread.currentThread().isInterrupted()) {
try {
var entry = queue.take();
Expand Down Expand Up @@ -213,7 +217,9 @@ public void dispose() {
disposed = true;
log.info("Disposing controller {}", name);

synchronizer.dispose();
if (synchronizer != null) {
synchronizer.dispose();
}

executor.shutdownNow();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public void addDocuments(List<PostDoc> posts) throws IOException {
var doc = this.convert(post);
try {
var seqNum =
writer.updateDocument(new Term(PostDoc.ID_FIELD, post.getName()), doc);
writer.updateDocument(new Term(PostDoc.ID_FIELD, post.name()), doc);
if (log.isDebugEnabled()) {
log.debug("Updated document({}) with sequence number {} returned",
post.getName(), seqNum);
post.name(), seqNum);
}
} catch (IOException e) {
throw Exceptions.propagate(e);
Expand Down Expand Up @@ -142,19 +142,19 @@ private Query buildQuery(String keyword) {

private Document convert(PostDoc post) {
var doc = new Document();
doc.add(new StringField("name", post.getName(), YES));
doc.add(new StoredField("title", post.getTitle()));
doc.add(new StringField("name", post.name(), YES));
doc.add(new StoredField("title", post.title()));

var content = Jsoup.clean(stripToEmpty(post.getExcerpt()) + stripToEmpty(post.getContent()),
var content = Jsoup.clean(stripToEmpty(post.excerpt()) + stripToEmpty(post.content()),
Safelist.none());

doc.add(new StoredField("content", content));
doc.add(new TextField("searchable", post.getTitle() + content, NO));
doc.add(new TextField("searchable", post.title() + content, NO));

long publishTimestamp = post.getPublishTimestamp().toEpochMilli();
long publishTimestamp = post.publishTimestamp().toEpochMilli();
doc.add(new LongPoint("publishTimestamp", publishTimestamp));
doc.add(new StoredField("publishTimestamp", publishTimestamp));
doc.add(new StoredField("permalink", post.getPermalink()));
doc.add(new StoredField("permalink", post.permalink()));
return doc;
}

Expand Down
44 changes: 21 additions & 23 deletions src/main/java/run/halo/app/search/post/PostDoc.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
package run.halo.app.search.post;

import java.time.Instant;
import lombok.Data;
import org.springframework.util.Assert;
import run.halo.app.theme.finders.vo.PostVo;

@Data
public class PostDoc {
public record PostDoc(String name,
String title,
String excerpt,
String content,
Instant publishTimestamp,
String permalink) {

public static final String ID_FIELD = "name";

private String name;

private String title;

private String excerpt;

private String content;

private Instant publishTimestamp;

private String permalink;
public PostDoc {
Assert.hasText(name, "Name must not be blank");
Assert.hasText(title, "Title must not be blank");
Assert.hasText(permalink, "Permalink must not be blank");
Assert.notNull(publishTimestamp, "PublishTimestamp must not be null");
}

// TODO Move this static method to other place.
public static PostDoc from(PostVo postVo) {
var post = new PostDoc();
post.setName(postVo.getMetadata().getName());
post.setTitle(postVo.getSpec().getTitle());
post.setExcerpt(postVo.getStatus().getExcerpt());
post.setPublishTimestamp(postVo.getSpec().getPublishTime());
post.setContent(postVo.getContent().getContent());
post.setPermalink(postVo.getStatus().getPermalink());
return post;
return new PostDoc(
postVo.getMetadata().getName(),
postVo.getSpec().getTitle(),
postVo.getStatus().getExcerpt(),
postVo.getContent().getContent(),
postVo.getSpec().getPublishTime(),
postVo.getStatus().getPermalink()
);
}

}
76 changes: 0 additions & 76 deletions src/main/java/run/halo/app/search/post/PostEventListener.java

This file was deleted.

Loading