feat(portal): WeChat QR onboarding + faster/cleaner contact search#52
Merged
Conversation
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.
What
Two portal upgrades, both validated live with Playwright against the real Beijing gateway:
1. QR onboarding
When the WeChat account is signed out, the portal now shows the gateway's
login QR and continues automatically once you scan it.
PortalService.qr()→ proxiesGET /api/auth/qr?type=base64, resolvesthe gateway's async UI task server-side (polls
/api/tasks/{id}, bounded to~10s), and hands the browser a ready-to-render data URL.
409 already logged inis surfaced as-is (never logs the account out).
/api/wechat/statusreportslogged_in: false), with a QR image, a RefreshQR button, and a 3s login poll that reloads the view once you're in.
2. Faster, cleaner contact search (fixes real UX issues found during E2E)
The admin search fetched all ~4,600 contacts serially (gateway caps
limit=200),so the first search blocked several seconds with no feedback, and groups
leaked into the person picker. Fixed:
ThreadPoolExecutor, 6 workers) + single-flight (aper-instance fetch lock) so overlapping searches and the background warm share
one fetch instead of each paging thousands of rows. Cold fetch dropped from
~7s to ~1s; warm hits are instant.
type=friendfilter → groups (e.g.…@chatroom) no longer pollute theadmin allowlist search.
load so the first real search is usually instant.
Tests
tests/test_channels_portal.pygains QR cases (inline result, task-polling,409already-logged-in). Full suite: 412 passed, 1 skipped (the 3 Windows-only
failures are pre-existing and pass on CI Linux). ruff clean.
Playwright E2E (real gateway)
Verified: portal loads, account resolves to AceDataCloud (online), contact
search
崔→ real friends with no group leak, group checkboxes →allowed_groups, Free-form ⇄ Require-prefix toggle, Save writes a validchannels.toml(round-trip confirmed on disk, then restored), and the QRonboarding card renders cleanly in light + dark mode.
🤖 对抗评审
Reviewer: Claude
general-purposesubagent (Codex not installed), read-only.VERDICT: CLEAN
Confirmed: per-instance fetch lock is created race-free under
self._lockandcorrectly dedupes (no redundant full fetches);
_contacts_cacheis alwayslock-guarded;
ThreadPoolExecutoris bounded (6) and closed viawith;httpx.Clientis thread-safe.
_fetch_all_contactscomputes offsets fromtotaland caps at_CONTACTS_MAX(falls back whentotalmissing); a per-page failure is swallowedbest-effort (documented tradeoff).
qr()polling is bounded (~10s, no infiniteloop), surfaces
409asPortalError(409)(not502), and never logs theaccount out. The gateway token stays server-side (never sent to the browser).
Frontend has no unhandled promise rejections and always clears the QR poll interval
before reuse. Ruff clean; Python 3.10 compatible.