(feat): add based maintenance to perform analyze + vacuum

It will help if your database has been runing for a very long time
This commit is contained in:
Eduard Tolosa 2025-07-26 22:25:27 -05:00
parent 88cbb3cc9b
commit 768bce39ec
2 changed files with 39 additions and 6 deletions

View file

@ -0,0 +1,25 @@
function __based_maintenance
set -l db ~/.local/share/fish/based/based.db
if not test -f $db
echo "Database not found. Run 'based init' first."
return 1
end
echo "Performing database maintenance..."
# Get database size before
set -l size_before (du -h $db | cut -f1)
# Vacuum the database
sqlite3 $db "VACUUM;"
# Update statistics
sqlite3 $db "ANALYZE;"
# Get database size after
set -l size_after (du -h $db | cut -f1)
echo "Database maintenance completed."
echo "Size before: $size_before"
echo "Size after: $size_after"
end

View file

@ -8,14 +8,22 @@ function based
__based_stats
case reset
__based_reset_state
case maintenance vacuum
__based_maintenance
case help '*'
echo "Usage: based init|import|stats|reset|help"
echo "Usage: based init|import|stats|reset|maintenance|help"
echo "Commands:"
echo " init - Initialize the Based database"
echo " import - Import fish history into Based"
echo " stats - Show Based statistics"
echo " reset - Reset Based state (clears variables)"
echo " maintenance - Perform database maintenance (vacuum & analyze)"
echo " help - Show this help message"
echo ""
echo "Configuration variables:"
echo " BASED_NO_CONFIRMATION - Skip confirmation prompts"
echo " BASED_NO_FUZZY - Disable fuzzy matching"
echo " BASED_EXCLUDED_PATHS - Paths to exclude from history (glob patterns)"
case '*'
echo "Unknown command: $argv[1]"
echo "Use 'based help' for usage information."