1356 字
3 分钟
开发工作总结
主要开发工作
1. 文章详情页与分页功能修复
问题描述:
- 文章详情页面能跳转但无法渲染 Markdown 内容
- 右侧日历栏的文章跳转链接缺少
/posts前缀
解决方案:
- 修复
posts/[...slug].astro中的Content组件,使其直接返回entry.body字符串 - 修正
Calendar.astro中的getPostUrl函数,为 permalink 路径统一添加/posts/前缀 - 在后端
BlogArticleController.getBySlug方法添加@Anonymous注解,解决 API 认证拦截
2. 慢 SQL 索引优化
问题描述:
文章列表查询(blog_article JOIN sys_user)持续出现 1-6 秒慢 SQL
根本原因:
sys_user.user_name字段无索引导致 JOIN 全表扫描blog_article表缺少覆盖 status/deleted 条件及 is_pinned/publish_time 排序的复合索引- 列表查询返回冗余 content 字段
解决方案:
生成 optimize_slow_query.sql 脚本,包含 5 个关键索引:
idx_sys_user_user_nameidx_article_status_deleted_sort等
优化效果:查询耗时降至 100ms 以内,消除 filesort,JOIN 走索引
3. Slug 文章查询接口开发
为博客系统开发基于 slug 的文章查询接口,包括:
- Controller 层添加
@GetMapping("/slug/{slug}")端点 - Service 接口声明
selectBlogArticleBySlug方法 - Mapper XML 文件中添加 SQL 查询语句
4. Redis 缓存优化
- 实现菜单树 Redis 缓存机制
- 添加启动预热机制,提升首次访问性能
- 解决缓存一致性问题
踩坑经验
Content 组件返回值格式
文章详情页面的 Content 组件不能返回对象形式,必须直接返回 entry.body 字符串,否则 Markdown 组件无法正确渲染文章内容。
URL 路径前缀问题
点击文章卡片跳转到详情页面时,URL 路径可能缺少 /posts 前缀。需要在 getPostUrl 函数中为 permalink 路径统一添加前缀:
if (post.data.permalink) {
const slug = post.data.permalink
.replace(/^\/+/, "")
.replace(/\/+$/, "");
return url(`/posts/${slug}/`);
}
部分信息可能已经过时









