Skip to content

fix(userInfo): 刷新失败时保留上次成功刷新的数值字段 - #1422

Open
fnyfree wants to merge 1 commit into
pt-plugins:masterfrom
fnyfree:fix/userinfo-keep-last-on-error
Open

fix(userInfo): 刷新失败时保留上次成功刷新的数值字段#1422
fnyfree wants to merge 1 commit into
pt-plugins:masterfrom
fnyfree:fix/userinfo-keep-last-on-error

Conversation

@fnyfree

@fnyfree fnyfree commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Closes #769

问题

站点用户信息刷新失败(Cloudflare 拦截、需要登录、解析错误等)时,AbstractPrivateSite.getUserInfoResult 返回仅含 {status, updateAt, site} 的最小错误对象,setSiteLastUserInfo 将其整体覆盖 metadata.lastUserInfo,导致 MyData 表格中上次成功获取的数值(上传量/下载量/分享率/魔力值等)消失(#769)。

正如报告者所述,站点被 CF 临时拦截是暂时性的,「过些时间就好了,但这段时间是没数据的」。

修复

setSiteLastUserInfo 中,当新数据 status !== success 上次数据为 success 时,将错误对象深合并到上次数据之上:

  • 保留旧数值字段(uploaded/downloaded/bonus/seeding…)
  • 错误对象中的字段优先(status/updateAt 及部分解析成功的新鲜字段)
  • 防护条件 previous.status === success 防止错误数据叠加
  • 成功路径不变,完整覆盖

效果:表格显示最后已知值 + 错误状态徽章<ResultParseStatus/> 原有渲染,UI 零改动)。

设计说明

  • 与既有设计一致getSiteUserInfoResult 中已有同语义的回退逻辑(站点不可查询时从历史挑最近一次 success 数据,见 userInfo.ts 原第 62-79 行「以避免 metadata.lastUserInfo 为 undefined」),本 PR 将该「最后已知值」语义延伸到刷新失败场景
  • Non-goal(明确不做):趋势图/统计的空档。历史存储(userInfo)仍仅在成功时写入——向历史写入非当期实测值属于伪造数据;图表数据源不受本 PR 影响

E2E 验证(Chrome for Testing + 实际构建扩展,5 场景)

场景 断言 结果
S1 失败保留旧值 success 数据 → CFBlocked → uploaded/bonus/name 保留,status=6,updateAt 更新
S2 成功正常覆盖 新 success → 完整覆盖
S3 无旧数据 新站点直接写错误 → 原样写入不崩溃
S4 错误不叠错误 错误后再写错误 → 不合并(防护生效)
S5 新鲜字段优先 错误对象携带部分新字段(name/seeding)→ 覆盖旧值,其余数值保留

校验

  • ✅ prettier 通过;vue-tsc 无新增错误

Summary by Sourcery

Bug Fixes:

  • 保留刷新失败前最近一次成功获取的用户数值字段,同时更新错误状态和时间信息。

站点用户信息刷新失败(Cloudflare 拦截、需要登录、解析错误等)时,
返回的最小错误对象会整体覆盖 metadata.lastUserInfo,导致 MyData
表格中上次成功获取的数值(上传量、下载量、魔力值等)消失。

现当新数据 status 非成功且上次数据为成功时,将错误对象合并到
上次数据之上(错误对象中的 status/updateAt 及部分解析成功的
新鲜字段优先覆盖),表格保留最后已知值并显示错误状态徽章。

历史存储(userInfo)仍仅在成功时写入,趋势图与统计不受影响。

Closes pt-plugins#769
Copilot AI lite review requested due to automatic review settings August 18, 2026 07:50
@sourcery-ai

sourcery-ai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds fallback merging logic when persisting user info so that on refresh failures the last successful numeric fields are preserved while error status and fresh fields still update.

File-Level Changes

Change Details Files
Preserve last successful user info values on refresh failure by deep-merging error results into prior successful metadata before storage.
  • Import toMerged helper from es-toolkit for deep merge operations.
  • Add conditional branch in setSiteLastUserInfo to detect non-success userData with a prior successful entry for the same site.
  • When conditions match, merge previous successful data with the new error object so that status/updateAt and any parsed fresh fields override while numeric metrics persist.
  • Leave successful-refresh behavior unchanged, still fully overwriting metadataStore.lastUserInfo for that site.
src/entries/offscreen/utils/userInfo.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#769 When refreshing site user data fails (e.g., CF block, login required, parse error), preserve the last successfully refreshed data in metadata so that existing values (upload/download, ratio, bonus, etc.) remain visible instead of being cleared.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 修复站点用户信息刷新失败时(如 Cloudflare 拦截、需要登录、解析错误)导致 metadata.lastUserInfo 被最小错误对象覆盖、从而使 MyData 表格“上次成功刷新”的关键数值字段(上传/下载/分享率/魔力值等)消失的问题(Closes #769)。修复点位于 offscreen 侧写入 lastUserInfo 的逻辑,通过在失败刷新时对“上次 success 的数据”进行合并回退,保留最后已知值并更新失败状态与时间戳。

Changes:

  • setSiteLastUserInfo 中:当本次刷新 status !== success 且上次缓存为 success 时,将错误对象合并覆盖到上次成功数据之上,以保留数值字段。
  • 引入 toMerged 深合并工具用于合并“上次成功值 + 本次错误状态/新鲜字段”。

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

保留上次刷新数据结果

2 participants