mirror of
https://github.com/zebrajr/ollama-webui.git
synced 2026-01-15 12:15:13 +00:00
feat/perf: Add ENABLE_PUBLIC_ACTIVE_USERS_COUNT environment variable (#20027)
* Merge pull request open-webui#19030 from open-webui/dev (#115) Co-authored-by: Tim Baek <tim@openwebui.com> Co-authored-by: Claude <noreply@anthropic.com> Resolves #13026 * Claude/find active user count 1ct t1 (#116) Co-authored-by: Tim Baek <tim@openwebui.com> Co-authored-by: Claude <noreply@anthropic.com> Resolves #13026 * Claude/find active user count 1ct t1 (#117) Co-authored-by: Tim Baek <tim@openwebui.com> Co-authored-by: Claude <noreply@anthropic.com> Resolves #13026 --------- Co-authored-by: Tim Baek <tim@openwebui.com> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -364,6 +364,11 @@ if DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL is not None:
|
|||||||
except Exception:
|
except Exception:
|
||||||
DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL = 0.0
|
DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL = 0.0
|
||||||
|
|
||||||
|
# Enable public visibility of active user count (when disabled, only admins can see it)
|
||||||
|
ENABLE_PUBLIC_ACTIVE_USERS_COUNT = (
|
||||||
|
os.environ.get("ENABLE_PUBLIC_ACTIVE_USERS_COUNT", "True").lower() == "true"
|
||||||
|
)
|
||||||
|
|
||||||
RESET_CONFIG_ON_START = (
|
RESET_CONFIG_ON_START = (
|
||||||
os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true"
|
os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -473,6 +473,7 @@ from open_webui.env import (
|
|||||||
EXTERNAL_PWA_MANIFEST_URL,
|
EXTERNAL_PWA_MANIFEST_URL,
|
||||||
AIOHTTP_CLIENT_SESSION_SSL,
|
AIOHTTP_CLIENT_SESSION_SSL,
|
||||||
ENABLE_STAR_SESSIONS_MIDDLEWARE,
|
ENABLE_STAR_SESSIONS_MIDDLEWARE,
|
||||||
|
ENABLE_PUBLIC_ACTIVE_USERS_COUNT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1848,6 +1849,7 @@ async def get_app_config(request: Request):
|
|||||||
"enable_login_form": app.state.config.ENABLE_LOGIN_FORM,
|
"enable_login_form": app.state.config.ENABLE_LOGIN_FORM,
|
||||||
"enable_websocket": ENABLE_WEBSOCKET_SUPPORT,
|
"enable_websocket": ENABLE_WEBSOCKET_SUPPORT,
|
||||||
"enable_version_update_check": ENABLE_VERSION_UPDATE_CHECK,
|
"enable_version_update_check": ENABLE_VERSION_UPDATE_CHECK,
|
||||||
|
"enable_public_active_users_count": ENABLE_PUBLIC_ACTIVE_USERS_COUNT,
|
||||||
**(
|
**(
|
||||||
{
|
{
|
||||||
"enable_direct_connections": app.state.config.ENABLE_DIRECT_CONNECTIONS,
|
"enable_direct_connections": app.state.config.ENABLE_DIRECT_CONNECTIONS,
|
||||||
@@ -2024,10 +2026,19 @@ async def get_current_usage(user=Depends(get_verified_user)):
|
|||||||
This is an experimental endpoint and subject to change.
|
This is an experimental endpoint and subject to change.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# If public visibility is disabled, only allow admins to access this endpoint
|
||||||
|
if not ENABLE_PUBLIC_ACTIVE_USERS_COUNT and user.role != "admin":
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
|
detail="Access denied. Only administrators can view usage statistics.",
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"model_ids": get_models_in_use(),
|
"model_ids": get_models_in_use(),
|
||||||
"user_count": Users.get_active_user_count(),
|
"user_count": Users.get_active_user_count(),
|
||||||
}
|
}
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Error getting usage statistics: {e}")
|
log.error(f"Error getting usage statistics: {e}")
|
||||||
raise HTTPException(status_code=500, detail="Internal Server Error")
|
raise HTTPException(status_code=500, detail="Internal Server Error")
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
import { getUsage } from '$lib/apis';
|
import { getUsage } from '$lib/apis';
|
||||||
import { getSessionUser, userSignOut } from '$lib/apis/auths';
|
import { getSessionUser, userSignOut } from '$lib/apis/auths';
|
||||||
|
|
||||||
import { showSettings, mobile, showSidebar, showShortcuts, user } from '$lib/stores';
|
import { showSettings, mobile, showSidebar, showShortcuts, user, config } from '$lib/stores';
|
||||||
|
|
||||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||||
|
|
||||||
@@ -59,9 +59,14 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$: if (show) {
|
const handleDropdownChange = (state: boolean) => {
|
||||||
getUsageInfo();
|
dispatch('change', state);
|
||||||
}
|
|
||||||
|
// Fetch usage info when dropdown opens, if user has permission
|
||||||
|
if (state && ($config?.features?.enable_public_active_users_count || role === 'admin')) {
|
||||||
|
getUsageInfo();
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ShortcutsModal bind:show={$showShortcuts} />
|
<ShortcutsModal bind:show={$showShortcuts} />
|
||||||
@@ -75,9 +80,7 @@
|
|||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
<DropdownMenu.Root
|
<DropdownMenu.Root
|
||||||
bind:open={show}
|
bind:open={show}
|
||||||
onOpenChange={(state) => {
|
onOpenChange={handleDropdownChange}
|
||||||
dispatch('change', state);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<DropdownMenu.Trigger>
|
<DropdownMenu.Trigger>
|
||||||
<slot />
|
<slot />
|
||||||
@@ -352,7 +355,7 @@
|
|||||||
<div class=" self-center truncate">{$i18n.t('Sign Out')}</div>
|
<div class=" self-center truncate">{$i18n.t('Sign Out')}</div>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
|
|
||||||
{#if showActiveUsers && usage}
|
{#if showActiveUsers && ($config?.features?.enable_public_active_users_count || role === 'admin') && usage}
|
||||||
{#if usage?.user_count}
|
{#if usage?.user_count}
|
||||||
<hr class=" border-gray-50/30 dark:border-gray-800/30 my-1 p-0" />
|
<hr class=" border-gray-50/30 dark:border-gray-800/30 my-1 p-0" />
|
||||||
|
|
||||||
@@ -364,7 +367,9 @@
|
|||||||
<div
|
<div
|
||||||
class="flex rounded-xl py-1 px-3 text-xs gap-2.5 items-center"
|
class="flex rounded-xl py-1 px-3 text-xs gap-2.5 items-center"
|
||||||
on:mouseenter={() => {
|
on:mouseenter={() => {
|
||||||
getUsageInfo();
|
if ($config?.features?.enable_public_active_users_count || role === 'admin') {
|
||||||
|
getUsageInfo();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class=" flex items-center">
|
<div class=" flex items-center">
|
||||||
|
|||||||
Reference in New Issue
Block a user