Repository navigation
One shared cache for read RPCs: useRpcData replaces useRPCLoad and useCachedResource - #29895
Open
chrisnojima wants to merge 4 commits into
Open
chrisnojima wants to merge 4 commits into
chrisnojima wants to merge 4 commits into
Conversation
…eCachedResource Read rpcs now go through one cache keyed by method and params (shared/query). Screens asking for the same data share a call and an answer, a change notice during a load costs one more load, a lost link reloads after the reconnect handshake, an account change empties the cache, and leaving the last screen cancels the call. Generated rpc functions carry their method name and take an abort signal. The per-resource caches, reload epochs and reconnect hook are removed.
A load still on the wire when the last screen leaves finishes and is cached. Forgotten data no longer reads as loading. An optimistic write drops an older load's answer. One notice heard by several listeners is one load, and team notices are debounced again. loaded means a load succeeded (settled covers a failed one), a failed load is reported once through onError, entries are emptied rather than removed, and list rows read the teams list through a plain cache reader.
A notice that arrives during a load no screen is waiting for keeps that answer stale. reloadAndWait and loadRpcIfStale wait for a queued follow-up load too. Idle data is dropped on a timer rather than when a new key happens to be created. A disabled instance never reports loading.
One notice heard by several listeners is counted once for the load, the stale flag and the debounce. A screen that mounts inside the failure backoff loads when it ends, and stale checks respect it. An optimistic write no longer strands a first load, and its writers refresh once the write settles. A superseded or failed reload keeps the staleness it was meant to cure, a lost link ends a wait with a load queued, forgotten data is not reloaded by notices, and readers subscribe to the data alone. Emptied entries let go of their closures, and data landing after its last screen left is still swept. Device revoke waits for its own load before closing, git row errors clear on the next load, and the bot role is asked for afresh per screen.
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 this does
Read RPCs now go through one cache, keyed by method and params and shared by every screen (
shared/query).useRpcDatareplacesuseRPCLoadanduseCachedResource; both old hooks,reload-epoch,use-reload-on-reconnectand every per-resource cache map, sign-out resetter and "private cache for disabled instances" workaround are deleted.All 28 call sites of the old hooks are migrated. Writes are unchanged: they stay plain
useRPC/*RpcPromisecalls and callrefreshRpc(rpc)orsetRpcData(...)afterwards where they need to.useLoadData(name, key, load, options)is the same thing for a load made of more than one call (loaded team, team channels, chat team members).useCachedRpcData(rpc, params, select)only reads what another screen loaded. List rows use it for the teams list.refreshRpc/refreshLoadsay the data changed;forgetLoaddrops data that no longer exists (a team left or deleted);loadRpcIfStalereloads only if a screen is loading it.The rules every read now follows
setRpcData) drops a load already on the wire; the writer callsrefreshRpconce its write has settled.shared/query/notifications.tsx.Generator change
Generated
*RpcPromisefunctions now carry their method name (rpc.method, used as the cache key) and take an optionalAbortSignalthird argument that cancels the call client-side through the engine.CallPortgainscancelSession. The regenerated files are included.Behaviour changes
loadedmeans a load succeeded.settledis "the attempt is over, with data or an error", which is whatuseRPCLoadcalledloaded. Device revoke, add-device and the git row usesettled.reload()supersedes a load already on the wire (its answer is dropped). Notices use the finish-then-one-more rule instead.Decisions for review
useQuery, so swapping the internals later would not touch call sites.:). The abort signal is still used when a load is superseded, forgotten, or the account changes.use-proof-suggestions.test.tsxreplaced the RPC function with a jest spy, which has no method name to key on. It now runs the same three cases against the fake engine.Testing
yarn lint:allclean, 0 compiler bailouts.yarn test:unit: 471 suites, 6,251 tests pass.teams-settings"description" and "showcase on my profile" fail on this branch and on the base branch alike (checked against a clean copy of base), so they are not in the list above.Not verified