mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[GH-ISSUE #8862] Introduce a Housekeeping Background Job - Automatic Cleanup of Associated Files Upon Chat Deletion #15295
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?
Originally created by @wggcch on GitHub (Jan 24, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/8862
Feature Request: Automatic Cleanup of Associated Files Upon Chat Deletion
Description
Problem Statement
When a user deletes a chat within Open WebUI, the related files—such as images, pdfs, text documents and audio files—remain stored in the system. Although these files are only accessible to users with file access permissions, they accumulate over time, potentially leading to unnecessary storage usage.
Proposed Solution
Introduce a background housekeeping task that activates whenever a user deletes a chat. This task, implemented using FastAPI’s BackgroundTasks, would:
• Trigger: Activate immediately after a chat deletion.
• Function: Scan for and identify files that are no longer associated with any active chats.
• Cleanup: Remove these “stale” files to free up storage and maintain system efficiency.
Suggested Implementation Example
To provide some guidance, here’s an example of how this can be achieved using FastAPI’s BackgroundTasks:
In this example:
• A cleanup_stale_files function is defined to handle the removal of files associated with the deleted chat.
• The /chats/{chat_id} endpoint deletes the specified chat and schedules the cleanup_stale_files function to run in the background.
• This ensures that the client receives an immediate response, while the cleanup operation occurs asynchronously.
Alternative Approaches Considered
While adding API endpoints to allow external systems or administrators to manually delete unused files is an option, automating this process with background tasks ensures consistency, reduces the potential for human error, and streamlines maintenance.
Benefits
• Efficient Storage Management: Automatically removes unnecessary files, preventing storage bloat.
• Enhanced Performance: Keeps the system lean, potentially improving overall performance.
• Improved User Experience: Ensures that deleted chats do not leave behind residual files, maintaining a clean and organized environment.
Implementation Considerations
• Security: Ensure that the cleanup task only removes files associated with the deleted chat and does not affect other users’ data.
• Performance Impact: Optimize the background task to minimize any impact on the system’s performance during peak usage times.
• Logging & Monitoring: Implement logging to track cleanup activities and monitor for any issues that may arise during the process.
Additional Context
Automating file cleanup aligns with best practices for system maintenance and data management. It helps in maintaining the integrity and efficiency of Open WebUI, especially as the user base grows and the volume of data increases.
Thank you for considering this feature request! I believe that implementing automatic cleanup will greatly enhance the usability and maintenance of Open WebUI. I’m happy to assist further or provide additional details if needed.