Implement database caching for Get-SfAccount function and improve test clarity#12
Implement database caching for Get-SfAccount function and improve test clarity#12
Conversation
| $result = Invoke-Expression -Command $Command | ||
|
|
||
| $result | ConvertTo-Json -Depth 100 | Out-File -FilePath $filePath | ||
| $json = $result | ConvertTo-Json -Depth 100 |
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
|
|
||
| $result | ConvertTo-Json -Depth 100 | Out-File -FilePath $filePath | ||
| $json = $result | ConvertTo-Json -Depth 100 | ||
|
|
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
| Write-Host $FileName | ||
| } Export-ModuleMember -Function Save-InvokeAsMockFile | ||
|
|
||
| function Save-InvokeAsMockFileJson{ |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Save-InvokeAsMockFileJson' does not have a help comment. Note
|
|
||
| $filePath = Get-MockFileFullPath -fileName $fileName | ||
|
|
||
| $result = Invoke-Expression -Command $Command |
Check warning
Code scanning / PSScriptAnalyzer
Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead. Warning
|
|
||
| $result | Out-File -FilePath $filePath | ||
|
|
||
| Write-Host $FileName |
Check warning
Code scanning / PSScriptAnalyzer
File 'InvokeCommandMock.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information. Warning
|
|
||
| "CacheKey : $cacheKey" | Write-Verbose | ||
|
|
||
| return $cacheKey |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'getcacheKey' returns an object of type 'System.String' but this type is not declared in the OutputType attribute. Note
| New-Item -Path $DATABASE_ROOT -ItemType Directory | ||
| } | ||
|
|
||
| function Reset-DatabaseStore{ |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Reset-DatabaseStore' does not have a help comment. Note
| New-Item -Path $DATABASE_ROOT -ItemType Directory | ||
| } | ||
|
|
||
| function Reset-DatabaseStore{ |
Check warning
Code scanning / PSScriptAnalyzer
Function 'Reset-DatabaseStore' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning
| param() | ||
|
|
||
| $databaseRoot = Invoke-MyCommand -Command GetDatabaseStorePath | ||
|
|
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
|
|
||
| } Export-ModuleMember -Function Reset-DatabaseStore | ||
|
|
||
| function Get-DatabaseStore{ |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Get-DatabaseStore' does not have a help comment. Note
| param() | ||
|
|
||
| $databaseRoot = Invoke-MyCommand -Command GetDatabaseStorePath | ||
|
|
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
| return $ret | ||
| } | ||
|
|
||
| function Reset-Database{ |
Check warning
Code scanning / PSScriptAnalyzer
Function 'Reset-Database' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning
|
|
||
| # Key file not exists | ||
| if(-Not (Test-Path $path)){ | ||
| return $false |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Test-Database' returns an object of type 'System.Boolean' but this type is not declared in the OutputType attribute. Note
|
|
||
| # TODO: Return $false if cache has expired | ||
|
|
||
| return $true |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Test-Database' returns an object of type 'System.Boolean' but this type is not declared in the OutputType attribute. Note
| return $path | ||
| } | ||
|
|
||
| function Invoke-GetDatabaseStorePath{ |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Invoke-GetDatabaseStorePath' does not have a help comment. Note
| Assert-Count -Expected 1 -Presented $dbfiles | ||
| Assert-IsTrue -Condition ($dbfiles[0].Name -like "sfDataQuery*-$type-$id-*.json") | ||
|
|
||
| # Remove sf data |
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
| New-Item -Path $CONFIG_ROOT -ItemType Directory | ||
| } | ||
|
|
||
| function Invoke-GetConfigRootPath { |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Invoke-GetConfigRootPath' does not have a help comment. Note
| } | ||
| catch { | ||
| Write-Warning "Error saving configuration ($Key) to file: $($path). $($_.Exception.Message)" | ||
| return $false |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Save-Configuration' returns an object of type 'System.Boolean' but this type is not declared in the OutputType attribute. Note
| return $false | ||
| } | ||
|
|
||
| return $true |
Check notice
Code scanning / PSScriptAnalyzer
The cmdlet 'Save-Configuration' returns an object of type 'System.Boolean' but this type is not declared in the OutputType attribute. Note
There was a problem hiding this comment.
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more
Development Environment:
.devcontainer/devcontainer.json.Module and Command Updates:
project-migration-moduletoSfHelperModuleinTest/private/InvokeCommandMock.ps1.Test_GetSfAccounttoTest_GetSfAccountFromUrlinTest/public/Get-SfObjectIdFromUrl.test.ps1.Database Management:
Test/private/mockdatabase.ps1.Reset-DatabaseStore,Get-DatabaseStore,Save-Database,Test-Database, andGetDatabaseFileinprivate/dependencies/databaseV2.ps1.Caching Mechanism:
public/sfDataQuery.ps1, including functions to test and save database cache and generate cache keys. [1] [2]These changes collectively enhance the project's robustness, performance, and maintainability.Introduce database caching for the Get-SfAccount function to enhance performance. Rename the test function for better clarity.