- 完成 CheckPermission 方法的完整实现(账号→角色→权限查询链) - 实现 Redis 缓存机制,大幅提升权限查询性能(~12倍提升) - 自动缓存失效:角色/权限变更时清除相关用户缓存 - 新增完整的单元测试和集成测试(10个测试用例全部通过) - 添加权限检查使用文档和缓存机制说明 - 归档 implement-permission-check OpenSpec 提案 性能优化: - 首次查询: ~18ms(3次DB查询 + 1次Redis写入) - 缓存命中: ~1.5ms(1次Redis查询) - TTL: 30分钟,自动失效机制保证数据一致性
35 lines
1.4 KiB
Go
35 lines
1.4 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
|
)
|
|
|
|
// stores 封装所有 Store 实例
|
|
// 注意:此结构体不导出,仅在 bootstrap 包内部使用
|
|
type stores struct {
|
|
Account *postgres.AccountStore
|
|
Shop *postgres.ShopStore
|
|
Role *postgres.RoleStore
|
|
Permission *postgres.PermissionStore
|
|
AccountRole *postgres.AccountRoleStore
|
|
RolePermission *postgres.RolePermissionStore
|
|
PersonalCustomer *postgres.PersonalCustomerStore
|
|
PersonalCustomerPhone *postgres.PersonalCustomerPhoneStore
|
|
// TODO: 新增 Store 在此添加字段
|
|
}
|
|
|
|
// initStores 初始化所有 Store 实例
|
|
func initStores(deps *Dependencies) *stores {
|
|
return &stores{
|
|
Account: postgres.NewAccountStore(deps.DB, deps.Redis),
|
|
Shop: postgres.NewShopStore(deps.DB, deps.Redis),
|
|
Role: postgres.NewRoleStore(deps.DB),
|
|
Permission: postgres.NewPermissionStore(deps.DB),
|
|
AccountRole: postgres.NewAccountRoleStore(deps.DB, deps.Redis),
|
|
RolePermission: postgres.NewRolePermissionStore(deps.DB, deps.Redis),
|
|
PersonalCustomer: postgres.NewPersonalCustomerStore(deps.DB, deps.Redis),
|
|
PersonalCustomerPhone: postgres.NewPersonalCustomerPhoneStore(deps.DB),
|
|
// TODO: 新增 Store 在此初始化
|
|
}
|
|
}
|