streams: Add bulk_access_stream_metadata_user_ids.

This function will be useful in sending events for users gaining or
losing metadata access when the members of a user group change in any
way.
This commit is contained in:
Shubham Padia
2025-03-20 08:29:51 +00:00
committed by Tim Abbott
parent 55ea5be022
commit 208ee1b8d9
3 changed files with 258 additions and 10 deletions

View File

@@ -141,16 +141,14 @@ def num_subscribers_for_stream_id(stream_id: int) -> int:
).count()
def get_user_ids_for_streams(stream_ids: set[int]) -> dict[int, set[int]]:
all_subs = (
get_active_subscriptions_for_stream_ids(stream_ids)
.values(
"recipient__type_id",
"user_profile_id",
)
.order_by(
"recipient__type_id",
)
def get_user_ids_for_stream_query(
query: QuerySet[Subscription, Subscription],
) -> dict[int, set[int]]:
all_subs = query.values(
"recipient__type_id",
"user_profile_id",
).order_by(
"recipient__type_id",
)
get_stream_id = itemgetter("recipient__type_id")
@@ -163,6 +161,18 @@ def get_user_ids_for_streams(stream_ids: set[int]) -> dict[int, set[int]]:
return result
def get_user_ids_for_streams(stream_ids: set[int]) -> dict[int, set[int]]:
return get_user_ids_for_stream_query(get_active_subscriptions_for_stream_ids(stream_ids))
def get_guest_user_ids_for_streams(stream_ids: set[int]) -> dict[int, set[int]]:
return get_user_ids_for_stream_query(
get_active_subscriptions_for_stream_ids(stream_ids).filter(
user_profile__role=UserProfile.ROLE_GUEST
)
)
def get_users_for_streams(stream_ids: set[int]) -> dict[int, set[UserProfile]]:
all_subs = (
get_active_subscriptions_for_stream_ids(stream_ids)