Skip to content

Commit 6296822

Browse files
authored
perf(scoop): Load libs only once (#4839)
1 parent 7ee74a0 commit 6296822

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+145
-186
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
- **scoop-download:** Add failure check ([#4822](https://github.com/ScoopInstaller/Scoop/pull/4822))
1616
- **install:** Fix issue with installation inside containers ([#4837](https://github.com/ScoopInstaller/Scoop/pull/4837))
1717

18+
### Performance Improvements
19+
20+
- **scoop:** Load libs only once ([#4839](https://github.com/ScoopInstaller/Scoop/issues/4839))
21+
1822
### Code Refactoring
1923

2024
- **bucket:** Move 'Find-Manifest' and 'list_buckets' to 'buckets' ([#4814](https://github.com/ScoopInstaller/Scoop/issues/4814))

bin/checkver.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ param(
6969
)
7070

7171
. "$PSScriptRoot\..\lib\core.ps1"
72+
. "$PSScriptRoot\..\lib\autoupdate.ps1"
7273
. "$PSScriptRoot\..\lib\manifest.ps1"
7374
. "$PSScriptRoot\..\lib\buckets.ps1"
74-
. "$PSScriptRoot\..\lib\autoupdate.ps1"
7575
. "$PSScriptRoot\..\lib\json.ps1"
7676
. "$PSScriptRoot\..\lib\versions.ps1"
7777
. "$PSScriptRoot\..\lib\install.ps1" # needed for hash generation
@@ -105,7 +105,7 @@ Get-Event | ForEach-Object {
105105
$Queue | ForEach-Object {
106106
$name, $json = $_
107107

108-
$substitutions = Get-VersionSubstitution $json.version
108+
$substitutions = Get-VersionSubstitution $json.version # 'autoupdate.ps1'
109109

110110
$wc = New-Object Net.Webclient
111111
if ($json.checkver.useragent) {
@@ -337,7 +337,7 @@ while ($in_progress -gt 0) {
337337
Write-Host 'Forcing autoupdate!' -ForegroundColor DarkMagenta
338338
}
339339
try {
340-
Invoke-AutoUpdate $App $Dir $json $ver $matchesHashtable
340+
Invoke-AutoUpdate $App $Dir $json $ver $matchesHashtable # 'autoupdate.ps1'
341341
} catch {
342342
if ($ThrowError) {
343343
throw $_

bin/scoop.ps1

+40-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,56 @@
11
#Requires -Version 5
2-
param($cmd)
2+
param($SubCommand)
33

4-
Set-StrictMode -off
4+
Set-StrictMode -Off
55

66
. "$PSScriptRoot\..\lib\core.ps1"
77
. "$PSScriptRoot\..\lib\buckets.ps1"
88
. "$PSScriptRoot\..\lib\commands.ps1"
9+
. "$PSScriptRoot\..\lib\help.ps1"
10+
911
# for aliases where there's a local function, re-alias so the function takes precedence
1012
$aliases = Get-Alias | Where-Object { $_.Options -notmatch 'ReadOnly|AllScope' } | ForEach-Object { $_.Name }
1113
Get-ChildItem Function: | Where-Object -Property Name -In -Value $aliases | ForEach-Object {
1214
Set-Alias -Name $_.Name -Value Local:$($_.Name) -Scope Script
1315
}
1416

15-
$commands = commands
16-
if ('--version' -contains $cmd -or (!$cmd -and '-v' -contains $args)) {
17-
Write-Host "Current Scoop version:"
18-
Invoke-Expression "git -C '$(versiondir 'scoop' 'current')' --no-pager log --oneline HEAD -n 1"
19-
Write-Host ""
17+
switch ($SubCommand) {
18+
({ $SubCommand -in @($null, '--help', '/?') }) {
19+
if (!$SubCommand -and $Args -eq '-v') {
20+
$SubCommand = '--version'
21+
} else {
22+
exec 'help'
23+
}
24+
}
25+
({ $SubCommand -eq '--version' }) {
26+
Write-Host 'Current Scoop version:'
27+
if ((Test-CommandAvailable git) -and (Test-Path "$PSScriptRoot\..\.git") -and (get_config SCOOP_BRANCH 'master') -ne 'master') {
28+
Invoke-Expression "git -C '$PSScriptRoot\..' --no-pager log --oneline HEAD -n 1"
29+
} else {
30+
$version = Select-String -Pattern '^## \[(v[\d.]+)\].*?([\d-]+)$' -Path "$PSScriptRoot\..\CHANGELOG.md"
31+
Write-Host $version.Matches.Groups[1].Value -ForegroundColor Cyan -NoNewline
32+
Write-Host " - Released at $($version.Matches.Groups[2].Value)"
33+
}
34+
Write-Host ''
2035

21-
Get-LocalBucket | ForEach-Object {
22-
$bucketLoc = Find-BucketDirectory $_ -Root
23-
if(Test-Path (Join-Path $bucketLoc '.git')) {
24-
Write-Host "'$_' bucket:"
25-
Invoke-Expression "git -C '$bucketLoc' --no-pager log --oneline HEAD -n 1"
26-
Write-Host ""
36+
Get-LocalBucket | ForEach-Object {
37+
$bucketLoc = Find-BucketDirectory $_ -Root
38+
if ((Test-Path (Join-Path $bucketLoc '.git')) -and (Test-CommandAvailable git)) {
39+
Write-Host "'$_' bucket:"
40+
Invoke-Expression "git -C '$bucketLoc' --no-pager log --oneline HEAD -n 1"
41+
Write-Host ''
42+
}
2743
}
2844
}
45+
({ $SubCommand -in (commands) }) {
46+
if ($Args -in @('-h', '--help', '/?')) {
47+
exec 'help' @($SubCommand)
48+
} else {
49+
exec $SubCommand $Args
50+
}
51+
}
52+
default {
53+
"scoop: '$SubCommand' isn't a scoop command. See 'scoop help'."
54+
exit 1
55+
}
2956
}
30-
elseif (@($null, '--help', '/?') -contains $cmd -or $args[0] -contains '-h') { exec 'help' $args }
31-
elseif ($commands -contains $cmd) { exec $cmd $args }
32-
else { "scoop: '$cmd' isn't a scoop command. See 'scoop help'."; exit 1 }

lib/autoupdate.ps1

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
<#
2-
TODO
3-
- clean up
4-
#>
5-
. "$PSScriptRoot\core.ps1"
6-
. "$PSScriptRoot\json.ps1"
7-
1+
# Must included with 'json.ps1'
82
function find_hash_in_rdf([String] $url, [String] $basename) {
93
$data = $null
104
try {

lib/buckets.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
. "$PSScriptRoot\core.ps1"
2-
31
$bucketsdir = "$scoopdir\buckets"
42

53
function Find-BucketDirectory {

lib/core.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ function show_app($app, $bucket, $version) {
918918

919919
function last_scoop_update() {
920920
# PowerShell 6 returns an DateTime Object
921-
$last_update = (scoop config lastupdate)
921+
$last_update = (get_config lastupdate)
922922

923923
if ($null -ne $last_update -and $last_update.GetType() -eq [System.String]) {
924924
try {
@@ -934,7 +934,7 @@ function is_scoop_outdated() {
934934
$last_update = $(last_scoop_update)
935935
$now = [System.DateTime]::Now
936936
if($null -eq $last_update) {
937-
scoop config lastupdate $now.ToString('o')
937+
set_config lastupdate $now.ToString('o')
938938
# enforce an update for the first time
939939
return $true
940940
}

lib/diagnostic.ps1

-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Diagnostic tests.
33
Return $true if the test passed, otherwise $false.
44
Use 'warn' to highlight the issue, and follow up with the recommended actions to rectify.
55
#>
6-
. "$PSScriptRoot\buckets.ps1"
7-
86
function check_windows_defender($global) {
97
$defender = Get-Service -Name WinDefend -ErrorAction SilentlyContinue
108
if (Test-CommandAvailable Get-MpPreference) {
@@ -55,4 +53,3 @@ function check_long_paths {
5553

5654
return $true
5755
}
58-

lib/install.ps1

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
. "$PSScriptRoot\core.ps1"
2-
. "$PSScriptRoot\autoupdate.ps1"
3-
. "$PSScriptRoot\buckets.ps1"
4-
51
function nightly_version($date, $quiet = $false) {
62
$date_str = $date.tostring("yyyyMMdd")
73
if (!$quiet) {

lib/manifest.ps1

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
. "$PSScriptRoot\core.ps1"
2-
. "$PSScriptRoot\autoupdate.ps1"
3-
41
function manifest_path($app, $bucket) {
52
fullpath "$(Find-BucketDirectory $bucket)\$(sanitary_path $app).json"
63
}
@@ -88,7 +85,7 @@ function supports_architecture($manifest, $architecture) {
8885
return -not [String]::IsNullOrEmpty((arch_specific 'url' $manifest $architecture))
8986
}
9087

91-
function generate_user_manifest($app, $bucket, $version) {
88+
function generate_user_manifest($app, $bucket, $version) { # 'autoupdate.ps1' 'buckets.ps1' 'manifest.ps1'
9289
$null, $manifest, $bucket, $null = Find-Manifest $app $bucket
9390
if ("$($manifest.version)" -eq "$version") {
9491
return manifest_path $app $bucket

lib/versions.ps1

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# versions
21
function Get-LatestVersion {
32
<#
43
.SYNOPSIS
@@ -29,7 +28,7 @@ function Get-LatestVersion {
2928
}
3029
}
3130

32-
function Select-CurrentVersion {
31+
function Select-CurrentVersion { # 'manifest.ps1'
3332
<#
3433
.SYNOPSIS
3534
Select current version of installed app, from 'current\manifest.json' or modified time of version directory

libexec/scoop-alias.ps1

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ param(
2323
[Switch]$verbose = $false
2424
)
2525

26-
. "$PSScriptRoot\..\lib\core.ps1"
27-
. "$PSScriptRoot\..\lib\help.ps1"
28-
. "$PSScriptRoot\..\lib\install.ps1"
26+
. "$PSScriptRoot\..\lib\install.ps1" # shim related
2927

3028
$script:config_alias = 'alias'
3129

libexec/scoop-bucket.ps1

-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
# scoop bucket known
2020
param($cmd, $name, $repo)
2121

22-
. "$PSScriptRoot\..\lib\core.ps1"
23-
. "$PSScriptRoot\..\lib\buckets.ps1"
24-
. "$PSScriptRoot\..\lib\help.ps1"
25-
2622
$usage_add = 'usage: scoop bucket add <name> [<repo>]'
2723
$usage_rm = 'usage: scoop bucket rm <name>'
2824

libexec/scoop-cache.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# scoop cache rm *
1313
param($cmd)
1414

15-
. "$PSScriptRoot\..\lib\help.ps1"
16-
1715
function cacheinfo($file) {
1816
$app, $version, $url = $file.Name -split '#'
1917
New-Object PSObject -Property @{ Name = $app; Version = $version; Length = $file.Length; URL = $url }

libexec/scoop-cat.ps1

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
param($app)
55

6-
. "$PSScriptRoot\..\lib\manifest.ps1"
7-
. "$PSScriptRoot\..\lib\install.ps1"
8-
. "$PSScriptRoot\..\lib\help.ps1"
6+
. "$PSScriptRoot\..\lib\json.ps1" # 'ConvertToPrettyJson'
7+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Find-Manifest' (indirectly)
98

109
if (!$app) { error '<app> missing'; my_usage; exit 1 }
1110

libexec/scoop-checkup.ps1

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Help: Performs a series of diagnostic tests to try to identify things that may
44
# cause problems with Scoop.
55

6-
. "$PSScriptRoot\..\lib\core.ps1"
76
. "$PSScriptRoot\..\lib\diagnostic.ps1"
87

98
$issues = 0

libexec/scoop-cleanup.ps1

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
# -g, --global Cleanup a globally installed app
1010
# -k, --cache Remove outdated download cache
1111

12-
. "$PSScriptRoot\..\lib\core.ps1"
13-
. "$PSScriptRoot\..\lib\manifest.ps1"
14-
. "$PSScriptRoot\..\lib\buckets.ps1"
15-
. "$PSScriptRoot\..\lib\versions.ps1"
1612
. "$PSScriptRoot\..\lib\getopt.ps1"
17-
. "$PSScriptRoot\..\lib\help.ps1"
18-
. "$PSScriptRoot\..\lib\install.ps1"
13+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Select-CurrentVersion' (indirectly)
14+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
15+
. "$PSScriptRoot\..\lib\install.ps1" # persist related
1916

2017
$opt, $apps, $err = getopt $args 'gk' 'global', 'cache'
2118
if ($err) { "scoop cleanup: $err"; exit 1 }

libexec/scoop-config.ps1

-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@
132132

133133
param($name, $value)
134134

135-
. "$PSScriptRoot\..\lib\core.ps1"
136-
. "$PSScriptRoot\..\lib\help.ps1"
137-
138135
if (!$name) {
139136
$scoopConfig
140137
} elseif ($name -like '--help') {

libexec/scoop-depends.ps1

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# Usage: scoop depends <app>
22
# Summary: List dependencies for an app
33

4-
. "$PSScriptRoot\..\lib\depends.ps1"
5-
. "$PSScriptRoot\..\lib\install.ps1"
6-
. "$PSScriptRoot\..\lib\manifest.ps1"
7-
. "$PSScriptRoot\..\lib\buckets.ps1"
84
. "$PSScriptRoot\..\lib\getopt.ps1"
9-
. "$PSScriptRoot\..\lib\decompress.ps1"
10-
. "$PSScriptRoot\..\lib\help.ps1"
5+
. "$PSScriptRoot\..\lib\depends.ps1" # 'Get-Dependency'
6+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'default_architecture'
117

128
$opt, $apps, $err = getopt $args 'a:' 'arch='
139
$app = $apps[0]

libexec/scoop-download.ps1

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
# -u, --no-update-scoop Don't update Scoop before downloading if it's outdated
1616
# -a, --arch <32bit|64bit> Use the specified architecture, if the app supports it
1717

18-
. "$PSScriptRoot\..\lib\manifest.ps1"
19-
. "$PSScriptRoot\..\lib\install.ps1"
20-
. "$PSScriptRoot\..\lib\help.ps1"
2118
. "$PSScriptRoot\..\lib\getopt.ps1"
19+
. "$PSScriptRoot\..\lib\json.ps1" # 'autoupdate.ps1' (indirectly)
20+
. "$PSScriptRoot\..\lib\autoupdate.ps1" # 'generate_user_manifest' (indirectly)
21+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'default_architecture' 'generate_user_manifest' 'Find-Manifest' (indirectly)
22+
. "$PSScriptRoot\..\lib\install.ps1"
2223

2324
$opt, $apps, $err = getopt $args 'fhua:' 'force', 'no-hash-check', 'no-update-scoop', 'arch='
2425
if ($err) { error "scoop download: $err"; exit 1 }

libexec/scoop-export.ps1

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
# Summary: Exports (an importable) list of installed apps
33
# Help: Lists all installed apps.
44

5-
. "$PSScriptRoot\..\lib\core.ps1"
6-
. "$PSScriptRoot\..\lib\versions.ps1"
7-
. "$PSScriptRoot\..\lib\manifest.ps1"
8-
. "$PSScriptRoot\..\lib\buckets.ps1"
5+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
6+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'default_architecture' 'Select-CurrentVersion' (indirectly)
97

108
$def_arch = default_architecture
119

libexec/scoop-help.ps1

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# Summary: Show help for a command
33
param($cmd)
44

5-
. "$PSScriptRoot\..\lib\core.ps1"
6-
. "$PSScriptRoot\..\lib\commands.ps1"
7-
. "$PSScriptRoot\..\lib\help.ps1"
8-
95
function print_help($cmd) {
106
$file = Get-Content (command_path $cmd) -raw
117

libexec/scoop-hold.ps1

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Usage: scoop hold <apps>
22
# Summary: Hold an app to disable updates
33

4-
. "$PSScriptRoot\..\lib\help.ps1"
5-
. "$PSScriptRoot\..\lib\manifest.ps1"
6-
. "$PSScriptRoot\..\lib\versions.ps1"
4+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'install_info' 'Select-CurrentVersion' (indirectly)
5+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
76

87
$apps = $args
98

libexec/scoop-home.ps1

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
# Summary: Opens the app homepage
33
param($app)
44

5-
. "$PSScriptRoot\..\lib\core.ps1"
6-
. "$PSScriptRoot\..\lib\help.ps1"
7-
. "$PSScriptRoot\..\lib\manifest.ps1"
8-
. "$PSScriptRoot\..\lib\buckets.ps1"
5+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Find-Manifest' (indirectly)
96

107
if ($app) {
118
$null, $manifest, $bucket, $null = Find-Manifest $app

libexec/scoop-info.ps1

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
# Options:
44
# -v, --verbose Show full paths and URLs
55

6-
. "$PSScriptRoot\..\lib\help.ps1"
7-
. "$PSScriptRoot\..\lib\install.ps1"
8-
. "$PSScriptRoot\..\lib\manifest.ps1"
9-
. "$PSScriptRoot\..\lib\versions.ps1"
106
. "$PSScriptRoot\..\lib\getopt.ps1"
7+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Find-Manifest' (indirectly)
8+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-InstalledVersion'
119

1210
$opt, $app, $err = getopt $args 'v' 'verbose'
1311
if ($err) { error "scoop info: $err"; exit 1 }

libexec/scoop-install.ps1

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
# -s, --skip Skip hash validation (use with caution!)
1818
# -a, --arch <32bit|64bit> Use the specified architecture, if the app supports it
1919

20-
. "$PSScriptRoot\..\lib\core.ps1"
21-
. "$PSScriptRoot\..\lib\manifest.ps1"
22-
. "$PSScriptRoot\..\lib\buckets.ps1"
23-
. "$PSScriptRoot\..\lib\decompress.ps1"
20+
. "$PSScriptRoot\..\lib\getopt.ps1"
21+
. "$PSScriptRoot\..\lib\json.ps1" # 'autoupdate.ps1' (indirectly)
22+
. "$PSScriptRoot\..\lib\autoupdate.ps1" # 'generate_user_manifest' (indirectly)
23+
. "$PSScriptRoot\..\lib\manifest.ps1" # 'default_architecture' 'generate_user_manifest' 'Select-CurrentVersion' (indirectly)
2424
. "$PSScriptRoot\..\lib\install.ps1"
25+
. "$PSScriptRoot\..\lib\decompress.ps1"
2526
. "$PSScriptRoot\..\lib\shortcuts.ps1"
2627
. "$PSScriptRoot\..\lib\psmodules.ps1"
2728
. "$PSScriptRoot\..\lib\versions.ps1"
28-
. "$PSScriptRoot\..\lib\help.ps1"
29-
. "$PSScriptRoot\..\lib\getopt.ps1"
3029
. "$PSScriptRoot\..\lib\depends.ps1"
3130

3231
$opt, $apps, $err = getopt $args 'gikusa:' 'global', 'independent', 'no-cache', 'no-update-scoop', 'skip', 'arch='

0 commit comments

Comments
 (0)