fix(filesystem): dedupe concurrent initial auth requests#1437
Merged
Conversation
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
修复并发首次授权时重复触发授权流程的问题。通过为每个网盘类型缓存进行中的授权 Promise,使并发的 AuthVerify 调用复用同一次授权过程,避免重复打开授权页、重复请求 token 与重复写入本地存储。
Changes:
- 新增
authTokenPromises缓存按NetDiskType去重的首次授权 Promise AuthVerify在缺少 token 时复用同一个进行中的授权 Promise,保存 token 仅执行一次- 新增并发首次授权的单元测试覆盖
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/filesystem/auth.ts | 引入 authTokenPromises 去重缓存,将首次授权流程封装为单个共享 Promise 并在结束时清理 |
| packages/filesystem/auth.test.ts | 新增并发首次授权的测试,验证仅打开一次授权页、仅请求一次 token、仅保存一次 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
修复首次授权场景下,并发调用
AuthVerify()时会重复触发授权流程的问题。当本地不存在 token 或 token 缺少
accessToken时,同一网盘类型的多个并发认证请求现在会复用同一个授权 Promise,避免重复打开授权页、重复请求 token、重复写入本地存储。主要改动
authTokenPromises,按网盘类型缓存首次授权中的 PromiseAuthVerify(netDiskType)在缺少 token 时复用同一次授权请求修复的问题
在多个同步任务或多个文件系统操作几乎同时触发认证时,如果当前没有可用 token,之前每个请求都会各自执行:
GetNetDiskToken这可能导致用户看到多个授权窗口,或者产生重复 token 请求。
本 PR 修复后,同一网盘类型的首次授权流程只会执行一次,其他并发请求等待同一个结果。
测试
新增单元测试覆盖: