Skip to content

Comments

Implement database caching for Get-SfAccount function and improve test clarity#12

Merged
rulasg merged 8 commits intomainfrom
rulasg/issue11
Mar 6, 2025
Merged

Implement database caching for Get-SfAccount function and improve test clarity#12
rulasg merged 8 commits intomainfrom
rulasg/issue11

Conversation

@rulasg
Copy link
Owner

@rulasg rulasg commented Mar 4, 2025

Development Environment:

  • Updated the development container image from Debian to Ubuntu in .devcontainer/devcontainer.json.

Module and Command Updates:

  • Changed module invocation tags from project-migration-module to SfHelperModule in Test/private/InvokeCommandMock.ps1.
  • Renamed the function Test_GetSfAccount to Test_GetSfAccountFromUrl in Test/public/Get-SfObjectIdFromUrl.test.ps1.

Database Management:

  • Added new functions for initializing and resetting the mock database in Test/private/mockdatabase.ps1.
  • Introduced comprehensive database management functions, including Reset-DatabaseStore, Get-DatabaseStore, Save-Database, Test-Database, and GetDatabaseFile in private/dependencies/databaseV2.ps1.

Caching Mechanism:

  • Implemented a caching mechanism for Salesforce data queries in 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.

@rulasg rulasg self-assigned this Mar 4, 2025
$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

Line has trailing whitespace

$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

Line has trailing whitespace
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

The cmdlet 'Save-InvokeAsMockFileJson' does not have a help comment.

$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

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead.

$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

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.

"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

The cmdlet 'getcacheKey' returns an object of type 'System.String' but this type is not declared in the OutputType attribute.
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

The cmdlet 'Reset-DatabaseStore' does not have a help comment.
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

Function 'Reset-DatabaseStore' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
param()

$databaseRoot = Invoke-MyCommand -Command GetDatabaseStorePath

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace

} Export-ModuleMember -Function Reset-DatabaseStore

function Get-DatabaseStore{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-DatabaseStore' does not have a help comment. Note

The cmdlet 'Get-DatabaseStore' does not have a help comment.
param()

$databaseRoot = Invoke-MyCommand -Command GetDatabaseStorePath

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
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

Function 'Reset-Database' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.

# 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

The cmdlet 'Test-Database' returns an object of type 'System.Boolean' but this type is not declared in the OutputType attribute.

# 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

The cmdlet 'Test-Database' returns an object of type 'System.Boolean' but this type is not declared in the OutputType attribute.
return $path
}

function Invoke-GetDatabaseStorePath{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Invoke-GetDatabaseStorePath' does not have a help comment. Note

The cmdlet 'Invoke-GetDatabaseStorePath' does not have a help comment.
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

Line has trailing whitespace
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

The cmdlet 'Invoke-GetConfigRootPath' does not have a help comment.
}
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

The cmdlet 'Save-Configuration' returns an object of type 'System.Boolean' but this type is not declared in the OutputType attribute.
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

The cmdlet 'Save-Configuration' returns an object of type 'System.Boolean' but this type is not declared in the OutputType attribute.
@rulasg rulasg requested a review from Copilot March 6, 2025 14:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

function Get-ModuleName{
$local = $PSScriptRoot | Split-Path -Parent | Split-Path -Parent
$moduleName = (Get-ChildItem -Path $local -Filter *.psd1 | Select-Object -First 1).BaseName

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
@rulasg rulasg merged commit 1f43f8c into main Mar 6, 2025
3 checks passed
@rulasg rulasg deleted the rulasg/issue11 branch March 6, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant