Fix: Add missing delete_time index to FileTrash table#8694
Open
yaoge123 wants to merge 3 commits intohaiwen:masterfrom
Open
Fix: Add missing delete_time index to FileTrash table#8694yaoge123 wants to merge 3 commits intohaiwen:masterfrom
yaoge123 wants to merge 3 commits intohaiwen:masterfrom
Conversation
The delete_time index is defined in the Python model (seafevents) with index=True but was missing from mysql.sql. This index is needed for the global cleanup query: WHERE delete_time < ? Without this index, the cleanup task performs a full table scan on FileTrash which can have millions of rows.
…ries Seadoc thumbnails use file_uuid as directory name, requiring a lookup from repo_id+path to uuid. The composite index (md5, filename, is_dir) eliminates table lookups by covering the full WHERE clause.
Avatar.objects.filter(emailuser=...) is used frequently throughout the codebase but lacked an index, causing full table scans.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Add missing delete_time index to FileTrash table
Problem
The
FileTrashtable is missing thedelete_timeindex that is defined in the Python model but never added tomysql.sql.Python Model Definition
File:
seafevents/events/models.pyCurrent mysql.sql (Missing Index)
Code Usage
Global Cleanup Query
File:
seafevents/events/db.pyQuery Pattern:
WHERE delete_time < ?Execution Context: Scheduled cleanup task (runs periodically)
Repository-level Cleanup
File:
seafevents/events/handlers.pyWhy This Index is Critical
WHERE delete_time < ?WHERE repo_id = ? AND delete_time < ?The Global Cleanup Problem
The scheduled cleanup task runs without a
repo_idfilter:Without the
delete_timeindex:Changes
Add the missing index to
sql/mysql.sql:Note on Compound Index
PR #8680 (seahub) / PR #606 (seafevents) also adds a compound index
(repo_id, delete_time)for the repository-specific query pattern:However, the single-column
delete_timeindex is still needed for:WHERE delete_time < ?without repo_id filter)(repo_id, delete_time)cannot satisfy queries that don't includerepo_idBoth indexes should coexist:
ix_FileTrash_delete_time(delete_time) - For global cleanupidx_filetrash_repo_delete_time(repo_id,delete_time) - For repo-specific queries (added in PR Remove redundant ix_FileTrash_repo_id index (covered by composite index in seafevents#606) #8680)Verification
This index is already defined in the Python model (
seafevents/events/models.py) but was simply forgotten inmysql.sql.