Version:0.0.6.dev.260204
feat: 🏗️ 在 sv/dao 层引入 ctx 支持链路追踪与超时控制(预留扩展) - 架构改造:在 sv 与 dao 层统一引入 ctx 🧩 - 为后续链路追踪、超时控制等能力提供支持 ⏱️(未来开发) perf: 🚀 为获取任务类列表接口引入 Redis 缓存并保证一致性 - 获取任务类列表接口新增 Redis 缓存提升访问速度 ⚡ - 通过新增任务类时主动删除缓存,确保主从一致性 ✅ - 防止缓存与数据库列表不一致问题 🛡️
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/LoveLosita/smartflow/backend/model"
|
||||
"github.com/LoveLosita/smartflow/backend/respond"
|
||||
@@ -29,7 +31,10 @@ func (api *TaskClassHandler) UserAddTaskClass(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
userIDInterface := c.GetInt("user_id")
|
||||
err = api.svc.AddTaskClass(&req, userIDInterface)
|
||||
// 创建一个带 1 秒超时的上下文
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 1*time.Second)
|
||||
defer cancel() // 记得释放资源
|
||||
err = api.svc.AddTaskClass(ctx, &req, userIDInterface)
|
||||
if err != nil {
|
||||
if errors.Is(err, respond.WrongParamType) {
|
||||
c.JSON(http.StatusBadRequest, respond.WrongParamType)
|
||||
@@ -42,7 +47,10 @@ func (api *TaskClassHandler) UserAddTaskClass(c *gin.Context) {
|
||||
|
||||
func (api *TaskClassHandler) UserGetTaskClassInfos(c *gin.Context) {
|
||||
userIDInterface := c.GetInt("user_id")
|
||||
resp, err := api.svc.GetUserTaskClassInfos(userIDInterface)
|
||||
// 创建一个带 1 秒超时的上下文
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 1*time.Second)
|
||||
defer cancel() // 记得释放资源
|
||||
resp, err := api.svc.GetUserTaskClassInfos(ctx, userIDInterface)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user