fix: 缓存击穿/play竞态/onUnload泄漏/清除数据UI/统计NaN

- leaderboard 云函数: _fetchLatestByOpenid 加 in-flight promise,并发请求复用同一次扫描,防缓存击穿
- voice: play 加序列号,丢弃过期播放,避免旧语音截断新语音
- timer: onUnload 补取消 _completionCountUp,系统返回手势不再泄漏动画定时器
- settings: 清除数据 setData 补 voiceGender/vibrateIntensity 重置,避免 UI 与存储不一致
- storage: getTotalStats 对 r.duration 防御(Number||0),避免脏数据产生 NaN 传染

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liucheng
2026-07-25 15:01:51 +08:00
parent 41aa81083f
commit 983ae1b9cb
5 changed files with 19 additions and 2 deletions
+4
View File
@@ -32,6 +32,7 @@ const FILEID_CACHE_KEY = 'tts_fileid_cache'
const LOCAL_CACHE_KEY = 'tts_local_cache' // { cacheKey: savedFilePath } - 持久本地文件,跨重启
let _ctx = null
let _playSeq = 0 // play 序列号,丢弃过期播放避免乱序
let _localCache = null // { cacheKey: savedFilePath } - persisted, lazy-loaded
const _urlCache = {} // { promptKey: audioUrl } — per-session, volatile
let _fileIDCache = null // { promptKey: fileID } — persisted, lazy-loaded
@@ -204,8 +205,11 @@ const preload = (keys) => {
*/
const play = async (promptKey) => {
if (!PROMPTS[promptKey]) return
const seq = ++_playSeq
const src = await _resolveSrc(promptKey)
if (!src) return
// 期间若有新的 play 调用,放弃本次,避免旧语音截断新语音
if (seq !== _playSeq) return
const ctx = _getCtx()
try {
ctx.stop()