mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
directly return number of active users from backend for usage display
This commit is contained in:
@@ -58,7 +58,7 @@ from open_webui.socket.main import (
|
||||
app as socket_app,
|
||||
periodic_usage_pool_cleanup,
|
||||
get_models_in_use,
|
||||
get_active_user_ids,
|
||||
get_active_users_count,
|
||||
)
|
||||
from open_webui.routers import (
|
||||
audio,
|
||||
@@ -1663,7 +1663,7 @@ async def get_current_usage(user=Depends(get_verified_user)):
|
||||
This is an experimental endpoint and subject to change.
|
||||
"""
|
||||
try:
|
||||
return {"model_ids": get_models_in_use(), "user_ids": get_active_user_ids()}
|
||||
return {"model_ids": get_models_in_use(), "users_count": get_active_users_count()}
|
||||
except Exception as e:
|
||||
log.error(f"Error getting usage statistics: {e}")
|
||||
raise HTTPException(status_code=500, detail="Internal Server Error")
|
||||
|
||||
@@ -152,6 +152,11 @@ def get_models_in_use():
|
||||
return models_in_use
|
||||
|
||||
|
||||
def get_active_users_count():
|
||||
"""Get the number of active users."""
|
||||
return len(USER_POOL)
|
||||
|
||||
|
||||
def get_active_user_ids():
|
||||
"""Get the list of active user IDs."""
|
||||
return list(USER_POOL.keys())
|
||||
|
||||
Reference in New Issue
Block a user