def get_user_activity_records_for_realm(realm: str, is_bot: bool) -> QuerySet:
    fields = ['user_profile__full_name', 'user_profile__delivery_email', 'query', 'client__name', 'count', 'last_visit']
    records = UserActivity.objects.filter(user_profile__realm__string_id=realm, user_profile__is_active=True, user_profile__is_bot=is_bot)
    records = records.order_by('user_profile__delivery_email', '-last_visit')
    records = records.select_related('user_profile', 'client').only(*fields)
    return records
def get_user_activity_records_for_realm(realm: str, is_bot: bool) -> QuerySet:
    fields = ['user_profile__full_name', 'user_profile__delivery_email', 'query', 'client__name', 'count', 'last_visit']
    records = UserActivity.objects.filter(user_profile__realm__string_id=realm, user_profile__is_active=True, user_profile__is_bot=is_bot)
    records = records.order_by('user_profile__delivery_email', '-last_visit')
    records = records.select_related('user_profile', 'client').only(*fields)
    return records