Files
FruitServer/sql/migrate-k113-session-platform-index.sql
Vicky 272aa62434 feat: phase1 UI prep — P1 安全(XFF防护), P2 规模化(平台索引+region保护), P3 文档补全
P1 安全: WebUtils.getClientIp 改为 remoteAddr 优先 + 可信代理 CIDR 配置
P2 规模化: DISTINCT ON 查询补匹配排序的部分索引 (migrate-k113)
P2 一致性: syncCountryByIp regionCode 同语言/时区/币种加保护,不覆盖用户自定义
P3 文档: api-phase1.md 新增 platform 参数说明, IpRegionService 新增集成测试 + VERSION
新增: CountryProfile 52 国映射 + IpRegionService 离线 ip2region 解析
平台筛选: app-users/favorites/likes/watch-history 按最近一次会话 ANDROID/IOS 筛选
2026-10-27 15:45:15 +08:00

12 lines
732 B
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Author: fruit.com.cn
-- K113 app_user_session 按「最近一次」平台筛选用户的索引。
--
-- selectUserIdsByLatestPlatform 用的是 DISTINCT ON (user_id) ... ORDER BY user_id, last_active_at DESC NULLS LAST, id DESC。
-- 原表只有 (user_id, revoked_at) 索引,DISTINCT ON + ORDER BY 退化成全表 Sort + Seq Scan,
-- 500 行还行,10 万行就扛不住了。补一个匹配 ORDER BY 的部分索引:deleted = 0 覆盖逻辑删除。
--
-- 注意:CREATE INDEX CONCURRENTLY 不能在事务块里执行,这里直接跑,不加 BEGIN/COMMIT。
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_session_user_latest
ON app_user_session (user_id, last_active_at DESC NULLS LAST, id DESC)
WHERE deleted = 0;