perf(mobile): speed up multi-environment reconnect on foreground #4885
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromt3code/speed-up-mobile-reconnectopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -0,0 +125,21 @@125+ .getItem(tokenKey(environmentId))126+ .pipe(Effect.mapError((cause) => tokenError("load", cause)));127+ if (raw === null) {128+ return yield* migrateLegacyToken(environmentId);129+ }130+ const decoded = yield* decodeRemoteDpopAccessToken(raw).pipe(131+ Effect.mapError((cause) => tokenError("decode", cause)),132+ Effect.catch((error) =>133+ Effect.logWarning("Discarding corrupt persisted environment access token", error).pipe(134+ Effect.andThen(135+ storage136+ .removeItem(tokenKey(environmentId))137+ .pipe(Effect.mapError((cause) => tokenError("delete", cause))),138+ ),139+ Effect.as(null),140+ ),141+ ),142+ );143+ if (decoded === null || decoded.environmentId !== environmentId) {144+ return Option.none<TokenStore.RemoteDpopAccessToken>();145+ }
- @@ -0,0 +5,21 @@5+import * as Encoding from "effect/Encoding";6+import * as Option from "effect/Option";7+import * as Ref from "effect/Ref";8+import * as Schema from "effect/Schema";9+import * as Semaphore from "effect/Semaphore";10+11+import * as MobileSecureStorage from "../persistence/mobile-secure-storage";12+import type { CatalogStore } from "./catalog-store";13+14+export const REMOTE_DPOP_TOKEN_KEY_PREFIX = "t3code.remote-dpop-token.";15+16+const RemoteDpopAccessTokenJson = Schema.fromJsonString(TokenStore.RemoteDpopAccessToken);17+const decodeRemoteDpopAccessToken = Schema.decodeEffect(RemoteDpopAccessTokenJson);18+const encodeRemoteDpopAccessToken = Schema.encodeEffect(RemoteDpopAccessTokenJson);19+20+function tokenError(operation: string, cause: unknown) {21+ return new ConnectionTransientError({22+ reason: "remote-unavailable",23+ detail: `Could not ${operation} the environment access token: ${String(cause)}`,24+ });25+}
- @@ -0,0 +124,21 @@124+ const raw = yield* storage125+ .getItem(tokenKey(environmentId))126+ .pipe(Effect.mapError((cause) => tokenError("load", cause)));127+ if (raw === null) {128+ return yield* migrateLegacyToken(environmentId);129+ }130+ const decoded = yield* decodeRemoteDpopAccessToken(raw).pipe(131+ Effect.mapError((cause) => tokenError("decode", cause)),132+ Effect.catch((error) =>133+ Effect.logWarning("Discarding corrupt persisted environment access token", error).pipe(134+ Effect.andThen(135+ storage136+ .removeItem(tokenKey(environmentId))137+ .pipe(Effect.mapError((cause) => tokenError("delete", cause))),138+ ),139+ Effect.as(null),140+ ),141+ ),142+ );143+ if (decoded === null || decoded.environmentId !== environmentId) {144+ return Option.none<TokenStore.RemoteDpopAccessToken>();
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
43042027-ca77-47d1-99d3-dee59bf588d3You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share