From b8b9ab9b638d4c0bb9ca2c4398bbd748322afc47 Mon Sep 17 00:00:00 2001 From: liweiyi <190785909@qq.com> Date: Thu, 28 Mar 2024 10:11:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=90=8E=E5=8F=B0=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E9=94=99=E8=AF=AF=E5=BC=95=E7=94=A8=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=EF=BC=8C=E8=AE=BF=E9=97=AE=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0host=E5=92=8Cpath=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E5=85=A8=E7=AB=99=E5=8F=91=E5=B8=83=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contentcore/service/ITemplateService.java | 67 +++++++++---------- .../service/impl/PublishServiceImpl.java | 12 +--- .../service/impl/TemplateServiceImpl.java | 43 +++++------- .../front/CmsStatApiController.java | 6 +- chestnut-ui/src/views/index.vue | 1 - 5 files changed, 55 insertions(+), 74 deletions(-) diff --git a/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/ITemplateService.java b/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/ITemplateService.java index f606f9f3..e3591bc9 100644 --- a/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/ITemplateService.java +++ b/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/ITemplateService.java @@ -15,103 +15,102 @@ */ package com.chestnut.contentcore.service; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.List; - import com.baomidou.mybatisplus.extension.service.IService; import com.chestnut.contentcore.domain.CmsSite; import com.chestnut.contentcore.domain.CmsTemplate; import com.chestnut.contentcore.domain.dto.TemplateAddDTO; -import com.chestnut.contentcore.domain.dto.TemplateRenameDTO; import com.chestnut.contentcore.domain.dto.TemplateUpdateDTO; import com.chestnut.contentcore.template.ITemplateType; +import java.io.File; +import java.io.IOException; +import java.util.List; + public interface ITemplateService extends IService { - void clearTemplateStaticContentCache(String templateId); + /** + * 清理站点指定模板静态化缓存 + * + * @param templateKey 唯一标识:相对resourceRoot路径 + */ + void clearTemplateStaticContentCache(String templateKey); /** + * 清理站点所有模板静态化缓存 + * + * @param site 站点信息 + */ + void clearSiteAllTemplateStaticContentCache(CmsSite site); + + /** * 获取模板类型 * - * @param typeid - * @return + * @param typeid 模板类型唯一标识 */ ITemplateType getTemplateType(String typeid); /** * 获取模板静态化内容缓存,主要区块模板使用 * - * @param templateId - * @return + * @param templateKey 相对resourceRoot路径 */ - String getTemplateStaticContentCache(String templateId); + String getTemplateStaticContentCache(String templateKey); /** * 缓存模板静态化内容 * - * @param templateId 相对resourceRoot路径 - * @param staticContent + * @param templateKey 相对resourceRoot路径 */ - void setTemplateStaticContentCache(String templateId, String staticContent); + void setTemplateStaticContentCache(String templateKey, String staticContent); /** * 扫描模板目录,创建模板数据库记录 * - * @param site + * @param site 站点数据 */ void scanTemplates(CmsSite site); /** * 保存模板内容 - * - * @throws IOException */ void saveTemplate(CmsTemplate template, TemplateUpdateDTO dto) throws IOException; /** * 模板文件重命名 * - * @param template - * @param path - * @param remark - * @param operator - * @throws IOException + * @param template 模板信息 + * @param path 路径 + * @param remark 备注 + * @param operator 操作人 */ void renameTemplate(CmsTemplate template, String path, String remark, String operator) throws IOException; /** * 获取模板文件 * - * @param template - * @return + * @param template 模板信息 */ File getTemplateFile(CmsTemplate template); /** * 查找模板文件 * - * @param site - * @param templatePath - * @param publishPipeCode - * @return - * @throws FileNotFoundException + * @param site 站点信息 + * @param templatePath 模板路径 + * @param publishPipeCode 发布通道编码 */ File findTemplateFile(CmsSite site, String templatePath, String publishPipeCode); /** * 新建模板文件 * - * @param dto - * @throws IOException + * @param dto 模板数据 */ void addTemplate(TemplateAddDTO dto) throws IOException; /** * 删除模板 - * @param templateIds - * @throws IOException + * @param templateIds 模板ID列表 */ void deleteTemplates(CmsSite site, List templateIds) throws IOException; } diff --git a/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/impl/PublishServiceImpl.java b/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/impl/PublishServiceImpl.java index 481ecbc8..2fe80ff4 100644 --- a/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/impl/PublishServiceImpl.java +++ b/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/impl/PublishServiceImpl.java @@ -48,7 +48,6 @@ import com.chestnut.contentcore.util.*; import com.chestnut.system.fixed.dict.YesOrNo; import freemarker.template.TemplateException; import lombok.RequiredArgsConstructor; -import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,15 +129,8 @@ public class PublishServiceImpl implements IPublishService, ApplicationContextAw @Override public void run0() throws InterruptedException { - List publishPipes = publishPipeService.getPublishPipes(site.getSiteId()); - publishPipes.forEach(pp -> { - try { - String siteRoot = SiteUtils.getSiteRoot(site, pp.getCode()); - FileUtils.deleteDirectory(new File(siteRoot + "include/")); - } catch (IOException e) { - logger.error("Delete site publish pipe include directory failed: {}", pp.getCode(), e); - } - }); + // 发布全站先清理所有模板缓存 + templateService.clearSiteAllTemplateStaticContentCache(site); List catalogList = catalogService .list(new LambdaQueryWrapper().eq(CmsCatalog::getSiteId, site.getSiteId())); diff --git a/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/impl/TemplateServiceImpl.java b/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/impl/TemplateServiceImpl.java index 49dfd522..2d213054 100644 --- a/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/impl/TemplateServiceImpl.java +++ b/chestnut-cms/chestnut-cms-contentcore/src/main/java/com/chestnut/contentcore/service/impl/TemplateServiceImpl.java @@ -17,7 +17,6 @@ package com.chestnut.contentcore.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.chestnut.common.redis.RedisCache; -import com.chestnut.common.utils.Assert; import com.chestnut.common.utils.IdUtils; import com.chestnut.common.utils.StringUtils; import com.chestnut.common.utils.file.FileExUtils; @@ -44,8 +43,6 @@ import org.springframework.stereotype.Service; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.Optional; @@ -67,19 +64,28 @@ public class TemplateServiceImpl extends ServiceImpl dbTemplates = this.lambdaQuery().eq(CmsTemplate::getSiteId, site.getSiteId()).list(); + dbTemplates.forEach(template -> { + String templateKey = SiteUtils.getTemplateKey(site, template.getPublishPipeCode(), template.getPath()); + clearTemplateStaticContentCache(templateKey); + }); } @Override @@ -153,14 +159,6 @@ public class TemplateServiceImpl extends ServiceImpl -