buzz icon indicating copy to clipboard operation
buzz copied to clipboard

communityMembershipProvider re-queries the relay on every session change and remount

Open meeveem opened this issue 2 months ago • 1 comments

Self-hosted relay, mobile client. Source pinned at c507a4d488ca27796e78d876b9c24ee38442cc1b.

Symptom

communityMembershipProvider re-queries the relay over HTTP on every session change and every remount, instead of caching the result.

mobile/lib/shared/community/community_membership_provider.dart:107:

final communityMembershipProvider =
    FutureProvider.autoDispose<CommunityMembershipSnapshot>((ref) async {
      ref.watch(relayConfigProvider);
      final session = ref.watch(relaySessionProvider.notifier);
      final events = await session.queryRelay([NostrFilters.relayMembers()]);
      return communityMembershipFromEvents(events);
    });

ref.watch(relaySessionProvider.notifier) invalidates the provider whenever the session notifier emits (reconnect, auth state change, socket drop), and autoDispose re-runs it on every remount. Each run is a fresh HTTP /query round-trip.

Observed consequence

In the relay's access log this shows up as repeated /query bursts, and the client additionally aborts in-flight requests (aborting with incomplete response / http2: stream closed in Caddy). Combined with the WebSocket dropping on idle, the app re-syncs rather than rendering from local state, which is what makes it feel slow on open.

Expected

Query once, keep the result, and refresh on an explicit signal (or via the WebSocket subscription) rather than on every session change and remount.

Where to look

  • mobile/lib/shared/community/community_membership_provider.dart
  • mobile/lib/shared/relay/relay_session.dart — queryRelay()

meeveem avatar Sep 18 '26 11:09 meeveem

Taking a look at this one — reproducing now, will follow up with a fix and a regression test.

UgaTheDev avatar Sep 18 '26 15:09 UgaTheDev