mirror of https://github.com/halo-dev/halo
feat: caching optimization
Add kind constants to Plugin and ExtensionPointDefinition classespull/6009/head
parent
ce44f57300
commit
620447287b
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.core.extension;
|
||||
|
||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
||||
import static run.halo.app.core.extension.Plugin.KIND;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
@ -27,10 +28,11 @@ import run.halo.app.infra.ConditionList;
|
|||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@GVK(group = "plugin.halo.run", version = "v1alpha1", kind = "Plugin", plural = "plugins",
|
||||
@GVK(group = "plugin.halo.run", version = "v1alpha1", kind = KIND, plural = "plugins",
|
||||
singular = "plugin")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Plugin extends AbstractExtension {
|
||||
public static final String KIND = "Plugin";
|
||||
|
||||
@Schema(requiredMode = REQUIRED)
|
||||
private PluginSpec spec;
|
||||
|
|
|
@ -5,8 +5,11 @@ import lombok.RequiredArgsConstructor;
|
|||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.core.extension.Plugin;
|
||||
import run.halo.app.core.extension.Role;
|
||||
import run.halo.app.extension.ReactiveExtensionClientImpl;
|
||||
import run.halo.app.infra.properties.HaloProperties;
|
||||
import run.halo.app.plugin.extensionpoint.ExtensionPointDefinition;
|
||||
|
||||
/**
|
||||
* Provides methods to determine if specific types of caches are evictable or enabled.
|
||||
|
@ -22,10 +25,6 @@ import run.halo.app.infra.properties.HaloProperties;
|
|||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CacheConditionProvider {
|
||||
private static final String ROLE_KIND = "Role";
|
||||
private static final String PLUGIN_KIND = "Plugin";
|
||||
private static final String EXTENSION_POINT_DEFINITION_KIND = "ExtensionPointDefinition";
|
||||
|
||||
private final HaloProperties properties;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +34,7 @@ public class CacheConditionProvider {
|
|||
* @return {@code true} if the role dependencies cache is evictable, {@code false} otherwise.
|
||||
*/
|
||||
public boolean isRoleDependenciesCacheEvictableByKind(String kind) {
|
||||
return isRoleCacheEnabled() && Objects.equals(kind, ROLE_KIND);
|
||||
return isRoleDependenciesCacheEnabled() && Objects.equals(kind, Role.KIND);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +44,7 @@ public class CacheConditionProvider {
|
|||
* @return {@code true} if the plugin extension cache is evictable, {@code false} otherwise.
|
||||
*/
|
||||
public boolean isPluginExtensionCacheEvictableByKind(String kind) {
|
||||
return isPluginExtensionCacheEnabled() && Objects.equals(kind, PLUGIN_KIND);
|
||||
return isPluginExtensionCacheEnabled() && Objects.equals(kind, Plugin.KIND);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,8 +55,8 @@ public class CacheConditionProvider {
|
|||
* otherwise.
|
||||
*/
|
||||
public boolean isExtensionPointDefinitionCacheEvictableByKind(String kind) {
|
||||
return isExtensionPointDefinitionCacheEnabled() && Objects.equals(kind,
|
||||
EXTENSION_POINT_DEFINITION_KIND);
|
||||
return isExtensionPointDefinitionCacheEnabled()
|
||||
&& Objects.equals(kind, ExtensionPointDefinition.KIND);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,7 +64,7 @@ public class CacheConditionProvider {
|
|||
*
|
||||
* @return {@code true} if the role dependencies cache is enabled, {@code false} otherwise
|
||||
*/
|
||||
public boolean isRoleCacheEnabled() {
|
||||
public boolean isRoleDependenciesCacheEnabled() {
|
||||
return isCacheEnabled("role-dependencies");
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public class DefaultRoleService implements RoleService {
|
|||
@Override
|
||||
@Cacheable(
|
||||
value = CacheNames.ROLE_DEPENDENCIES,
|
||||
condition = "@cacheConditionProvider.isRoleCacheEnabled()"
|
||||
condition = "@cacheConditionProvider.isRoleDependenciesCacheEnabled()"
|
||||
)
|
||||
public Flux<Role> listDependenciesFlux(Set<String> names) {
|
||||
return listDependencies(names, shouldFilterHidden(false));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.plugin.extensionpoint;
|
||||
|
||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
||||
import static run.halo.app.plugin.extensionpoint.ExtensionPointDefinition.KIND;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
@ -22,9 +23,10 @@ import run.halo.app.extension.GVK;
|
|||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@GVK(group = "plugin.halo.run", version = "v1alpha1",
|
||||
kind = "ExtensionPointDefinition", singular = "extensionpointdefinition",
|
||||
kind = KIND, singular = "extensionpointdefinition",
|
||||
plural = "extensionpointdefinitions")
|
||||
public class ExtensionPointDefinition extends AbstractExtension {
|
||||
public static final String KIND = "ExtensionPointDefinition";
|
||||
|
||||
@Schema(requiredMode = REQUIRED)
|
||||
private ExtensionPointSpec spec;
|
||||
|
|
Loading…
Reference in New Issue