mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #13396] [CLOSED] WIP: add periodic data cleanup task #38821
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/13396
Author: @CallumJHays
Created: 5/1/2025
Status: ❌ Closed
Base:
dev← Head:periodic-data-cleanup-task📝 Commits (5)
b6a9f83fix: db unbound error if connection failsc5ce52ftests(fix): always use absolute imports to prevent various issues (eg. isinstance)580882ftest(refactor): Add AbstractDBTest and AbstractSQLiteTestc21dc5afeat: add periodic data cleanup taskb8be8f3test(refactor): truncate tables in teardown using orm📊 Changes
12 files changed (+488 additions, -64 deletions)
View changed files
➕
backend/open_webui/data_cleanup_task.py(+243 -0)📝
backend/open_webui/env.py(+1 -0)📝
backend/open_webui/internal/db.py(+6 -6)📝
backend/open_webui/main.py(+4 -0)📝
backend/open_webui/test/apps/webui/routers/test_auths.py(+2 -2)📝
backend/open_webui/test/apps/webui/routers/test_chats.py(+2 -2)📝
backend/open_webui/test/apps/webui/routers/test_models.py(+2 -2)📝
backend/open_webui/test/apps/webui/routers/test_prompts.py(+2 -2)📝
backend/open_webui/test/apps/webui/routers/test_users.py(+2 -2)➕
backend/open_webui/test/test_data_cleanup_task.py(+182 -0)📝
backend/open_webui/test/util/abstract_integration_test.py(+41 -47)📝
backend/open_webui/test/util/mock_user.py(+1 -1)📄 Description
Adds periodic
apschedulerjob for implementing data retention policy by deleting expired db chat table rows, associated records, and cache files. Only supportssqliteandpostgresdatabases.Discussion: https://github.com/open-webui/open-webui/discussions/7465
Pull Request Checklist
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Added
DATA_CLEANUP_ENABLED (bool, default False): Whether to enable the data cleanup policy.DATA_CLEANUP_MAX_CHAT_AGE_DAYS (float): Sets the threshold for max chat age in days after which chats are deleted from DB, and uploaded files removed. Required ifDATA_CLEANUP_ENABLED.DATA_CLEANUP_MAX_CACHE_AGE_DAYS (float): Sets the threshold for max cache file age after which files are deleted (from the /app/data/cache/[audio|image] folders). Required ifDATA_CLEANUP_ENABLED.DATA_CLEANUP_CRON_SCHEDULE (str): Crontab schedule for the cleanup job eg: "0 * * * *" (the top of every hour). Required ifDATA_CLEANUP_ENABLED.DATA_CLEANUP_LOG_LEVEL (str, default "INFO"): Sets the log level for the data_cleanup_policy module. EG:"DEBUG" | "INFO"etc🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.