countGroupMemberships method

Future<Map<String, int>> countGroupMemberships()

Counts distinct group IDs across the nodes routing table. Returns a map of groupId → member count for updating the group directory.

Implementation

Future<Map<String, int>> countGroupMemberships() async {
  final allNodes = await getAllNodes();
  final counts = <String, int>{};
  for (final node in allNodes) {
    final gid = node.groupId;
    if (gid != null && gid != '*') {
      counts[gid] = (counts[gid] ?? 0) + 1;
    }
  }
  return counts;
}