Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Jan 27, 2024
2 parents 2776721 + 1be470a commit b4da7b0
Show file tree
Hide file tree
Showing 58 changed files with 1,318 additions and 1,907 deletions.
10 changes: 4 additions & 6 deletions api/src/main/java/run/halo/app/core/extension/content/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import run.halo.app.extension.GVK;
import run.halo.app.extension.GroupVersionKind;
import run.halo.app.extension.MetadataOperator;
import run.halo.app.extension.MetadataUtil;
import run.halo.app.infra.ConditionList;

/**
Expand All @@ -35,6 +34,8 @@ public class Post extends AbstractExtension {

public static final String KIND = "Post";

public static final String REQUIRE_SYNC_ON_STARTUP_INDEX_NAME = "requireSyncOnStartup";

public static final GroupVersionKind GVK = GroupVersionKind.fromExtension(Post.class);

public static final String CATEGORIES_ANNO = "content.halo.run/categories";
Expand Down Expand Up @@ -158,6 +159,8 @@ public static class PostStatus {

private Instant lastModifyTime;

private Long observedVersion;

@JsonIgnore
public ConditionList getConditionsOrDefault() {
if (this.conditions == null) {
Expand Down Expand Up @@ -268,9 +271,4 @@ public CompactPost build() {
}
}
}

public static void changePublishedState(Post post, boolean value) {
Map<String, String> labels = MetadataUtil.nullSafeLabels(post);
labels.put(PUBLISHED_LABEL, String.valueOf(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private void resolveStaticResources(Plugin plugin) {
log.info("Resolving logo resource for plugin {}", pluginName);
// the logo might be:
// 1. URL
// 2. file name
// 2. relative path to "resources" folder
// 3. base64 format data image
var logo = specLogo;
if (!specLogo.startsWith("data:image")) {
Expand All @@ -249,7 +249,8 @@ private void resolveStaticResources(Plugin plugin) {
} catch (MalformedURLException ignored) {
// indicate the logo is a path
logo = UriComponentsBuilder.newInstance()
.pathSegment("plugins", pluginName, "assets", specLogo)
.pathSegment("plugins", pluginName, "assets")
.path(specLogo)
.queryParam("version", pluginVersion)
.build(true)
.toString();
Expand All @@ -262,8 +263,8 @@ private void resolveStaticResources(Plugin plugin) {
var p = pluginManager.getPlugin(pluginName);
var classLoader = p.getPluginClassLoader();
var resLoader = new DefaultResourceLoader(classLoader);
var entryRes = resLoader.getResource("classpath:/console/main.js");
var cssRes = resLoader.getResource("classpath:/console/style.css");
var entryRes = resLoader.getResource("classpath:console/main.js");
var cssRes = resLoader.getResource("classpath:console/style.css");
if (entryRes.exists()) {
var entry = UriComponentsBuilder.newInstance()
.pathSegment("plugins", pluginName, "assets", "console", "main.js")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static run.halo.app.extension.ExtensionUtil.addFinalizers;
import static run.halo.app.extension.ExtensionUtil.removeFinalizers;
import static run.halo.app.extension.index.query.QueryFactory.equal;

import com.google.common.hash.Hashing;
import java.time.Instant;
Expand Down Expand Up @@ -36,6 +37,7 @@
import run.halo.app.event.post.PostUnpublishedEvent;
import run.halo.app.event.post.PostUpdatedEvent;
import run.halo.app.event.post.PostVisibleChangedEvent;
import run.halo.app.extension.DefaultExtensionMatcher;
import run.halo.app.extension.ExtensionClient;
import run.halo.app.extension.ExtensionOperator;
import run.halo.app.extension.ListOptions;
Expand Down Expand Up @@ -211,7 +213,11 @@ public Result reconcile(Request request) {
status.setInProgress(
!StringUtils.equals(headSnapshot, post.getSpec().getReleaseSnapshot()));

// version + 1 is required to truly equal version
// as a version will be incremented after the update
status.setObservedVersion(post.getMetadata().getVersion() + 1);
client.update(post);

// fire event after updating post
events.forEach(eventPublisher::publishEvent);
});
Expand All @@ -222,8 +228,12 @@ public Result reconcile(Request request) {
public Controller setupWith(ControllerBuilder builder) {
return builder
.extension(new Post())
// TODO Make it configurable
.workerCount(1)
.onAddMatcher(DefaultExtensionMatcher.builder(client, Post.GVK)
.fieldSelector(FieldSelector.of(
equal(Post.REQUIRE_SYNC_ON_STARTUP_INDEX_NAME, BooleanUtils.TRUE))
)
.build()
)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public Controller setupWith(ControllerBuilder builder) {

private void registerReverseProxy(ReverseProxy reverseProxy) {
String pluginId = getPluginId(reverseProxy);
routerFunctionRegistry.register(pluginId, reverseProxy).block();
routerFunctionRegistry.register(pluginId, reverseProxy);
}

private void cleanUpResources(ReverseProxy reverseProxy) {
String pluginId = getPluginId(reverseProxy);
routerFunctionRegistry.remove(pluginId, reverseProxy.getMetadata().getName()).block();
routerFunctionRegistry.remove(pluginId, reverseProxy.getMetadata().getName());
}

private void addFinalizerIfNecessary(ReverseProxy oldReverseProxy) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package run.halo.app.infra;

import com.github.zafarkhaja.semver.Version;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Objects;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.info.BuildProperties;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
Expand All @@ -17,21 +16,19 @@
public class DefaultSystemVersionSupplier implements SystemVersionSupplier {
private static final String DEFAULT_VERSION = "0.0.0";

@Nullable
private BuildProperties buildProperties;
private final ObjectProvider<BuildProperties> buildProperties;

@Autowired(required = false)
public void setBuildProperties(@Nullable BuildProperties buildProperties) {
public DefaultSystemVersionSupplier(ObjectProvider<BuildProperties> buildProperties) {
this.buildProperties = buildProperties;
}

@Override
public Version get() {
if (buildProperties == null) {
var properties = buildProperties.getIfUnique();
if (properties == null) {
return Version.valueOf(DEFAULT_VERSION);
}
String projectVersion =
StringUtils.defaultString(buildProperties.getVersion(), DEFAULT_VERSION);
var projectVersion = Objects.toString(properties.getVersion(), DEFAULT_VERSION);
return Version.valueOf(projectVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static run.halo.app.extension.index.IndexAttributeFactory.simpleAttribute;

import java.util.Set;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.boot.context.event.ApplicationContextInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.lang.NonNull;
Expand Down Expand Up @@ -146,6 +147,18 @@ public void onApplicationEvent(@NonNull ApplicationContextInitializedEvent event
.setName("status.excerpt")
.setIndexFunc(
simpleAttribute(Post.class, post -> post.getStatusOrDefault().getExcerpt())));

indexSpecs.add(new IndexSpec()
.setName(Post.REQUIRE_SYNC_ON_STARTUP_INDEX_NAME)
.setIndexFunc(simpleAttribute(Post.class, post -> {
var version = post.getMetadata().getVersion();
var observedVersion = post.getStatusOrDefault().getObservedVersion();
if (observedVersion == null || observedVersion < version) {
return BooleanUtils.TRUE;
}
// do not care about the false case so return null to avoid indexing
return null;
})));
});
schemeManager.register(Category.class, indexSpecs -> {
indexSpecs.add(new IndexSpec()
Expand Down

This file was deleted.

Loading

0 comments on commit b4da7b0

Please sign in to comment.