feat(leaderboard): 训练完强刷 + 下拉刷新 force

- 云函数 _fetchLatestByOpenid 支持 force 跳过实例缓存重新扫描
- 训练完成设 _lb_force_refresh 标志,下次打开排行榜强刷,新数据立即可见
- 下拉刷新带 force=true,拉取最新数据
- 平时常规打开仍走 5min 缓存 + 客户端乐观缓存,不增加无谓扫描

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-28 08:47:41 +08:00
parent e2becc24aa
commit b42d080826
4 changed files with 22 additions and 15 deletions
+14 -9
View File
@@ -35,16 +35,20 @@ Page({
const tb = this.getTabBar()
if (tb) tb.setData({ selected: 2 })
} catch (e) {}
if (this._firstShow) {
this._firstShow = false
this.fetchRank()
return
}
this.fetchRank()
// 训练完设的强刷标志:下次进排行榜跳过云函数缓存,立刻拿到含新记录的数据
let force = false
try {
if (wx.getStorageSync('_lb_force_refresh')) {
force = true
wx.removeStorageSync('_lb_force_refresh')
}
} catch (e) {}
this._firstShow = false
this.fetchRank(undefined, force)
},
onPullDownRefresh() {
this.fetchRank(() => wx.stopPullDownRefresh())
this.fetchRank(() => wx.stopPullDownRefresh(), true)
},
switchPeriod(e) {
@@ -54,7 +58,7 @@ Page({
this.fetchRank()
},
fetchRank(cb) {
fetchRank(cb, force) {
// 序列号:快速切换周期时丢弃旧响应,避免旧 period 的数据覆盖新 period
this._fetchSeq = (this._fetchSeq || 0) + 1
const seq = this._fetchSeq
@@ -81,7 +85,8 @@ Page({
name: 'leaderboard',
data: {
period,
maxRank: config.leaderboardMaxRank
maxRank: config.leaderboardMaxRank,
force: !!force
}
}).then(res => {
if (seq !== this._fetchSeq) { if (cb) cb(); return } // 过期响应,丢弃