move labeler cache to mmkv, make moderation config sync

The per-account labeler cache was the only async dependency in
configureModerationForAccount. MMKV-backed sync reads let session
bundle prep apply labelers in the same tick. No AsyncStorage
backfill: the cache is rewritten on every preferences fetch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-07-19 13:19:44 +03:00
parent 4d25c884c7
commit 63dad6320e
3 changed files with 13 additions and 15 deletions
+2 -3
View File
@@ -39,8 +39,7 @@ import {
} from '#/state/queries/preferences/types'
import {createQueryKey} from '#/state/queries/util'
import {useAppviewClient, usePdsClient} from '#/state/session'
import {saveLabelers} from '#/state/session/agent-config'
import {applyLabelersToClient} from '#/state/session/moderation'
import {applyLabelersToClient, saveLabelers} from '#/state/session/moderation'
import {useAgeAssurance} from '#/ageAssurance'
import {makeAgeRestrictedModerationPrefs} from '#/ageAssurance/util'
import {useAnalytics} from '#/analytics'
@@ -76,7 +75,7 @@ export function usePreferencesQuery() {
const labelerDids = res.moderationPrefs.labelers.map(l => l.did)
// save to local storage to ensure there are labels on initial requests
void saveLabelers(client.did, labelerDids)
saveLabelers(client.did, labelerDids)
/*
* Sync the subscribed labelers to the live appview client, mirroring the
-12
View File
@@ -1,12 +0,0 @@
import AsyncStorage from '@react-native-async-storage/async-storage'
const PREFIX = 'agent-labelers'
export async function saveLabelers(did: string, value: string[]) {
await AsyncStorage.setItem(`${PREFIX}:${did}`, JSON.stringify(value))
}
export async function readLabelers(did: string): Promise<string[] | undefined> {
const rawData = await AsyncStorage.getItem(`${PREFIX}:${did}`)
return rawData ? JSON.parse(rawData) : undefined
}
+11
View File
@@ -108,4 +108,15 @@ export type Account = {
* account after a switch, until that account's preferences loaded.
*/
isBetaUser?: boolean
/**
* The account's subscribed labeler DIDs, cached from preferences so the
* `atproto-accept-labelers` header can be configured synchronously at
* session start, before preferences load. Eventually consistent: rewritten
* on every preferences fetch (see `saveLabelers` in
* `#/state/session/moderation`). Until the first fetch lands there is
* simply no cache entry and initial requests go out without per-account
* labeler headers.
*/
labelers?: string[]
}