Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: generate summaries only for content changes #7200

Merged
merged 1 commit into from
Jan 20, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public enum Constant {
public static final String PERMALINK_PATTERN_ANNO = "content.halo.run/permalink-pattern";

public static final String CHECKSUM_CONFIG_ANNO = "checksum/config";

public static final String CONTENT_CHECKSUM_ANNO = "checksum/content";
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import run.halo.app.extension.ExtensionClient;
import run.halo.app.extension.ExtensionOperator;
import run.halo.app.extension.ListOptions;
import run.halo.app.extension.MetadataUtil;
import run.halo.app.extension.Ref;
import run.halo.app.extension.controller.Controller;
import run.halo.app.extension.controller.ControllerBuilder;
Expand Down Expand Up @@ -386,6 +387,16 @@ private String getExcerpt(Post post) {
return StringUtils.EMPTY;
}
var content = contentWrapper.get();

var contentChecksum = Hashing.sha256().hashString(content.getContent(), UTF_8).toString();
var annotations = MetadataUtil.nullSafeAnnotations(post);
var oldChecksum = annotations.get(Constant.CONTENT_CHECKSUM_ANNO);
if (Objects.equals(oldChecksum, contentChecksum)) {
return post.getStatusOrDefault().getExcerpt();
}
// update the checksum and generate new excerpt
annotations.put(Constant.CONTENT_CHECKSUM_ANNO, contentChecksum);

var tags = listTagDisplayNames(post);

var keywords = new HashSet<>(tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.springframework.web.util.UriUtils.encodePath;

import com.google.common.hash.Hashing;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
Expand All @@ -25,6 +26,7 @@
import run.halo.app.content.comment.CommentService;
import run.halo.app.core.counter.CounterService;
import run.halo.app.core.counter.MeterUtils;
import run.halo.app.core.extension.content.Constant;
import run.halo.app.core.extension.content.Post;
import run.halo.app.core.extension.content.SinglePage;
import run.halo.app.core.extension.content.Snapshot;
Expand Down Expand Up @@ -372,6 +374,16 @@ private String getExcerpt(SinglePage singlePage) {
return StringUtils.EMPTY;
}
var content = contentWrapper.get();

var contentChecksum = Hashing.sha256().hashString(content.getContent(), UTF_8).toString();
var annotations = MetadataUtil.nullSafeAnnotations(singlePage);
var oldChecksum = annotations.get(Constant.CONTENT_CHECKSUM_ANNO);
if (Objects.equals(oldChecksum, contentChecksum)) {
return singlePage.getStatusOrDefault().getExcerpt();
}
// update the checksum and generate new excerpt
annotations.put(Constant.CONTENT_CHECKSUM_ANNO, contentChecksum);

var context = new ExcerptGenerator.Context()
.setRaw(content.getRaw())
.setContent(content.getContent())
Expand Down
Loading