From 768bce39ecda71e17ee3fb98ee1e7f8f7aec7038 Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Sat, 26 Jul 2025 22:25:27 -0500 Subject: [PATCH] (feat): add `based maintenance` to perform analyze + vacuum It will help if your database has been runing for a very long time --- functions/__based_maintenance.fish | 25 +++++++++++++++++++++++++ functions/based.fish | 20 ++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 functions/__based_maintenance.fish diff --git a/functions/__based_maintenance.fish b/functions/__based_maintenance.fish new file mode 100644 index 0000000..6827113 --- /dev/null +++ b/functions/__based_maintenance.fish @@ -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 diff --git a/functions/based.fish b/functions/based.fish index cc2e0ae..bd49892 100644 --- a/functions/based.fish +++ b/functions/based.fish @@ -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 " help - Show this help message" + 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."