From 20c7e9f77a67fff2235cc99bac50644331662648 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Mon, 13 May 2024 20:30:49 +0800 Subject: [PATCH 1/3] fix(sqlite): Dispose all command to release database file handle --- lib/database.ps1 | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/lib/database.ps1 b/lib/database.ps1 index e15720d7da..5289199125 100644 --- a/lib/database.ps1 +++ b/lib/database.ps1 @@ -38,31 +38,6 @@ function Get-SQLite { } } -<# -.SYNOPSIS - Close a SQLite database. -.DESCRIPTION - Close a SQLite database connection. -.PARAMETER InputObject - System.Data.SQLite.SQLiteConnection - The SQLite database connection to close. -.INPUTS - System.Data.SQLite.SQLiteConnection -.OUTPUTS - None -#> -function Close-ScoopDB { - [CmdletBinding()] - param ( - [Parameter(Mandatory, ValueFromPipeline)] - [System.Data.SQLite.SQLiteConnection] - $InputObject - ) - process { - $InputObject.Dispose() - } -} - <# .SYNOPSIS Create a new SQLite database. @@ -164,6 +139,8 @@ function Set-ScoopDBItem { $dbTrans.Rollback() throw $_ } finally { + $dbCommand.Dispose() + $dbTrans.Dispose() $db.Dispose() } } @@ -292,6 +269,7 @@ function Select-ScoopDBItem { [void]$dbAdapter.Fill($result) } end { + $dbAdapter.Dispose() $db.Dispose() return $result } @@ -353,6 +331,7 @@ function Get-ScoopDBItem { [void]$dbAdapter.Fill($result) } end { + $dbAdapter.Dispose() $db.Dispose() return $result } From f67f4d6b51a83df408dde4e4f6fb7d4ac07c8a92 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Mon, 13 May 2024 20:35:20 +0800 Subject: [PATCH 2/3] Update chglog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53d07d6f51..e8c3322789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Features -- **scoop-search:** Use SQLite for caching apps to speed up local search ([#5851](https://github.com/ScoopInstaller/Scoop/issues/5851), [#5918](https://github.com/ScoopInstaller/Scoop/issues/5918), [#5946](https://github.com/ScoopInstaller/Scoop/issues/5946), [#5949](https://github.com/ScoopInstaller/Scoop/issues/5949), [#5955](https://github.com/ScoopInstaller/Scoop/issues/5955)) +- **scoop-search:** Use SQLite for caching apps to speed up local search ([#5851](https://github.com/ScoopInstaller/Scoop/issues/5851), [#5918](https://github.com/ScoopInstaller/Scoop/issues/5918), [#5946](https://github.com/ScoopInstaller/Scoop/issues/5946), [#5949](https://github.com/ScoopInstaller/Scoop/issues/5949), [#5955](https://github.com/ScoopInstaller/Scoop/issues/5955), [#5966](https://github.com/ScoopInstaller/Scoop/issues/5966)) - **core:** New cache filename format ([#5929](https://github.com/ScoopInstaller/Scoop/issues/5929)) ### Bug Fixes From 975521fa89062b2a6784d4110f1541fd3c5f61f5 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Mon, 13 May 2024 20:46:53 +0800 Subject: [PATCH 3/3] refactor(database): Rename `New-ScoopDB()` to `Open-ScoopDB()` --- lib/database.ps1 | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/database.ps1 b/lib/database.ps1 index 5289199125..6ca35ce1a4 100644 --- a/lib/database.ps1 +++ b/lib/database.ps1 @@ -40,22 +40,16 @@ function Get-SQLite { <# .SYNOPSIS - Create a new SQLite database. + Open Scoop SQLite database. .DESCRIPTION - Create a new SQLite database connection and create the necessary tables. -.PARAMETER PassThru - System.Management.Automation.SwitchParameter - Return the SQLite database connection. + Open Scoop SQLite database connection and create the necessary tables if not exists. .INPUTS None .OUTPUTS - None - Default - System.Data.SQLite.SQLiteConnection The SQLite database connection if **PassThru** is used. #> -function New-ScoopDB ([switch]$PassThru) { +function Open-ScoopDB { # Load System.Data.SQLite if (!('System.Data.SQLite.SQLiteConnection' -as [Type])) { try { @@ -87,11 +81,7 @@ function New-ScoopDB ([switch]$PassThru) { )" $tableCommand.ExecuteNonQuery() | Out-Null $tableCommand.Dispose() - if ($PassThru) { - return $db - } else { - $db.Dispose() - } + return $db } <# @@ -116,7 +106,7 @@ function Set-ScoopDBItem { ) begin { - $db = New-ScoopDB -PassThru + $db = Open-ScoopDB $dbTrans = $db.BeginTransaction() # TODO Support [hashtable]$InputObject $colName = @($InputObject | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name) @@ -254,7 +244,7 @@ function Select-ScoopDBItem { ) begin { - $db = New-ScoopDB -PassThru + $db = Open-ScoopDB $dbAdapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter $result = New-Object System.Data.DataTable $dbQuery = "SELECT * FROM app WHERE $(($From -join ' LIKE @Pattern OR ') + ' LIKE @Pattern')" @@ -310,7 +300,7 @@ function Get-ScoopDBItem { ) begin { - $db = New-ScoopDB -PassThru + $db = Open-ScoopDB $dbAdapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter $result = New-Object System.Data.DataTable $dbQuery = 'SELECT * FROM app WHERE name = @Name AND bucket = @Bucket'