async def list_users(request: Request) -> HTTPResponse: user_service = UserService(request[REQUEST_DB_SESSION_KEY]) username_query = utils.default_arg(request, "username", None) role_query = utils.default_arg(request, "role", None) users = user_service.fetch_all_users(config.team_name, username_query, role_query) if not users: return rasa_x_utils.error(404, "NoUsersFound", "No users found") profiles = [user_service.fetch_user(u["username"]) for u in users] return response.json(profiles, headers={"X-Total-Count": len(profiles)})
def run_analytics_caching() -> None: import rasax.community.database.utils as database_utils with database_utils.session_scope() as session: # Use new session for all sql operations analytics_service = AnalyticsService(session) now = time.time() user_service = UserService(session) platform_users = user_service.fetch_all_users(config.team_name) platform_user_ids = [u["username"] for u in platform_users] for k, v in CACHED_ANALYTICS_CONFIG.items(): window = rasa_x_utils.duration_to_seconds(v["window"]) start = now - rasa_x_utils.duration_to_seconds(v["range"]) for include_platform_users in [False, True]: result = analytics_service.calculate_analytics( start, now, window, platform_user_ids) analytics_service._persist_analytics( k, result, include_platform_users)