-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: enhance cache management in plugin setting config (#6141)
#### What type of PR is this? /kind feature /area plugin /area core /milestone 2.17.x #### What this PR does / why we need it: 增强插件配置的缓存管理 1. 通过 SettingFetcher/ReactiveSettingFetcher 获取插件配置可以不在考虑获取数据的性能问题,当数据变更后会自动更新缓存 2. 现在你可以通过在插件中监听 `PluginConfigUpdatedEvent` 事件来做一些处理,它会在用户更改插件配置后被触发 #### Does this PR introduce a user-facing change? ```release-note 增强插件配置的缓存管理并支持通过监听 `PluginConfigUpdatedEvent` 事件做一些特殊处理 ```
- Loading branch information
Showing
11 changed files
with
326 additions
and
74 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
api/src/main/java/run/halo/app/plugin/PluginConfigUpdatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package run.halo.app.plugin; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.Map; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.context.ApplicationEvent; | ||
import run.halo.app.core.extension.Plugin; | ||
import run.halo.app.extension.ConfigMap; | ||
|
||
/** | ||
* <p>Event that is triggered when the {@link ConfigMap } represented by | ||
* {@link Plugin.PluginSpec#getConfigMapName()} in the {@link Plugin} is updated.</p> | ||
* <p>has two properties, oldConfig and newConfig, which represent the {@link ConfigMap#getData()} | ||
* property value of the {@link ConfigMap}.</p> | ||
* | ||
* @author guqing | ||
* @since 2.17.0 | ||
*/ | ||
@Getter | ||
public class PluginConfigUpdatedEvent extends ApplicationEvent { | ||
private final Map<String, JsonNode> oldConfig; | ||
private final Map<String, JsonNode> newConfig; | ||
|
||
@Builder | ||
public PluginConfigUpdatedEvent(Object source, Map<String, JsonNode> oldConfig, | ||
Map<String, JsonNode> newConfig) { | ||
super(source); | ||
this.oldConfig = oldConfig; | ||
this.newConfig = newConfig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
application/src/main/java/run/halo/app/plugin/DefaultPluginGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package run.halo.app.plugin; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
import run.halo.app.core.extension.Plugin; | ||
import run.halo.app.extension.ExtensionClient; | ||
import run.halo.app.infra.exception.NotFoundException; | ||
|
||
/** | ||
* Default implementation of {@link PluginGetter}. | ||
* | ||
* @author guqing | ||
* @since 2.17.0 | ||
*/ | ||
@Component | ||
@RequiredArgsConstructor | ||
public class DefaultPluginGetter implements PluginGetter { | ||
private final ExtensionClient client; | ||
|
||
@Override | ||
public Plugin getPlugin(String name) { | ||
if (StringUtils.isBlank(name)) { | ||
throw new IllegalArgumentException("Plugin name must not be blank"); | ||
} | ||
return client.fetch(Plugin.class, name) | ||
.orElseThrow(() -> new NotFoundException("Plugin not found")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
application/src/main/java/run/halo/app/plugin/PluginGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package run.halo.app.plugin; | ||
|
||
import run.halo.app.core.extension.Plugin; | ||
import run.halo.app.infra.exception.NotFoundException; | ||
|
||
/** | ||
* An interface to get {@link Plugin} by name. | ||
* | ||
* @author guqing | ||
* @since 2.17.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface PluginGetter { | ||
|
||
/** | ||
* Get plugin by name. | ||
* | ||
* @param name plugin name must not be null | ||
* @return plugin | ||
* @throws IllegalArgumentException if plugin name is null | ||
* @throws NotFoundException if plugin not found | ||
*/ | ||
Plugin getPlugin(String name); | ||
} |
15 changes: 0 additions & 15 deletions
15
application/src/main/java/run/halo/app/plugin/SharedApplicationContext.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.