重构:统一应用服务与基础设施适配边界
将账号、认证、管理员、分析、自动化、卡券、聊天、商品、关键词、设置和订单能力迁移到 application 与 adapter,删除 Server 内对应的旧仓储和业务服务实现,并收紧架构检查。 完善批量发布与订单刷新生命周期、凭证写回、账号任务补偿、订单 reconciliation、通知和敏感数据边界;补充正常、失败、取消、并发、越权及多方言回归测试,并修正 MySQL 延迟任务表的 InnoDB 配置。 修复空卡密响应为 null 时前端加载失败的问题,重建嵌入式前端资产;重写重构总计划,清除历史流水并明确阶段 1 至 10 各对应一次完整迭代和一个 PR。 验证:make check;make test-server-race;npm test/typecheck/comments:check/build;Docker SQLite/MySQL 8.4/PostgreSQL 17 TestMultiDB_*。
This commit is contained in:
1 parent
19a7d5f924
commit
375e84d663
239 files changed
+23870
-7871
No files matched your search
@@ -2,42 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"errors"
|
||||
|
||||
"xianyu-go/internal/db"
|
||||
"xianyu-go/internal/xianyu/cookierefresh"
|
||||
"xianyu-go/internal/xianyu/mtop"
|
||||
"xianyu-go/internal/adapter"
|
||||
accountapp "xianyu-go/internal/application/account"
|
||||
)
|
||||
|
||||
// withMTopCookieSnapshot 为一次业务 MTOP 流程挂载账号 Cookie 会话。有完整
|
||||
// Jar 时保持所有作用域;历史账号则使用不冒充完整 Jar 的 flat session,仍能
|
||||
// 在成功或失败路径观察并持久化 Set-Cookie。
|
||||
// withMTopCookieSnapshot 负责withMTop登录凭证Snapshot相关处理。
|
||||
func withMTopCookieSnapshot(ctx context.Context, detail *db.CookieDetail) (context.Context, *mtop.CookieSession) {
|
||||
if detail == nil {
|
||||
return ctx, nil
|
||||
}
|
||||
// snapshot、ok 保存snapshot、ok,供当前处理流程使用
|
||||
snapshot, ok := cookierefresh.SnapshotFromMetadataOK(detail.MetadataJSON)
|
||||
if !ok {
|
||||
return mtop.WithFlatCookieSession(ctx, detail.Value)
|
||||
}
|
||||
return mtop.WithCookieSnapshot(ctx, snapshot)
|
||||
}
|
||||
|
||||
// hasStoredCookieCredential 负责hasStored登录凭证Credential相关处理。
|
||||
func hasStoredCookieCredential(detail *db.CookieDetail) bool {
|
||||
if detail == nil {
|
||||
return false
|
||||
}
|
||||
if detail.Value != "" {
|
||||
return true
|
||||
}
|
||||
// complete 保存complete,供当前处理流程使用
|
||||
_, complete := cookierefresh.SnapshotFromMetadataOK(detail.MetadataJSON)
|
||||
return complete
|
||||
}
|
||||
|
||||
// persistMTopCookieSessionLocked 原子保存业务 MTOP 响应后的完整 Cookie Jar。
|
||||
// 调用方必须持有账号凭证锁,并且 detail 必须是加锁后重读的最新记录。
|
||||
// handled 表示本次请求由完整 Cookie Jar 接管,或 session 已产生可持久化更新;
|
||||
@@ -46,28 +16,13 @@ func hasStoredCookieCredential(detail *db.CookieDetail) bool {
|
||||
// persistMTopCookieSessionLocked 负责persistMTop登录凭证会话Locked相关处理。
|
||||
func (s *Server) persistMTopCookieSessionLocked(
|
||||
ctx context.Context,
|
||||
detail *db.CookieDetail,
|
||||
session *mtop.CookieSession,
|
||||
detail *accountapp.CredentialDetail,
|
||||
session *adapter.CookieSession,
|
||||
) (value string, valueChanged, handled bool, err error) {
|
||||
if detail == nil || session == nil {
|
||||
return "", false, false, nil
|
||||
if s == nil {
|
||||
return "", false, true, errors.New("cookie 会话持久化服务未初始化")
|
||||
}
|
||||
// value、snapshot、changed 保存value、snapshot、changed,供当前处理流程使用
|
||||
value, snapshot, changed := session.State()
|
||||
if !changed {
|
||||
if snapshot != nil {
|
||||
return detail.Value, false, true, nil
|
||||
}
|
||||
return "", false, false, nil
|
||||
}
|
||||
// metadata 保存metadata,供当前处理流程使用
|
||||
metadata := cookierefresh.MetadataWithoutSnapshot(detail.MetadataJSON)
|
||||
if snapshot != nil {
|
||||
metadata = cookierefresh.MetadataWithSnapshot(detail.MetadataJSON, snapshot)
|
||||
}
|
||||
if // err 保存err,供当前处理流程使用
|
||||
err := s.Store.Cookies.UpdateRenewalCookie(ctx, detail.ID, value, metadata, time.Now().Unix()); err != nil {
|
||||
return value, value != detail.Value, true, err
|
||||
}
|
||||
return value, value != detail.Value, true, nil
|
||||
// repository 负责在凭证适配器内保存 Cookie 与加密 metadata;Server 不直接访问 Store。
|
||||
repository := s.accountLoginRepositoryForServer()
|
||||
return adapter.PersistCookieSessionLocked(ctx, repository, detail, session)
|
||||
}
|
||||
Reference in new issue
Block a user