Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-GSDriveFileList and memory usage #38

Closed
indented-automation opened this issue May 2, 2018 · 2 comments
Closed

Get-GSDriveFileList and memory usage #38

indented-automation opened this issue May 2, 2018 · 2 comments
Assignees

Comments

@indented-automation
Copy link

When querying large file drive structures the responses are grouped and held in memory by the Get-GSDriveFileList command.

This occurs because of the unnecessary use of array concatenation using the response variable in the block below.

$response = @()
[int]$i = 1
do {
    $result = $request.Execute()
    $response += $result.Files | Select-Object @{N = 'User';E = {$User}},*
    if ($result.NextPageToken) {
        $request.PageToken = $result.NextPageToken
    }
    [int]$retrieved = ($i + $result.Files.Count) - 1
    Write-Verbose "Retrieved $retrieved Files..."
    [int]$i = $i + $result.Files.Count
}
until (!$result.NextPageToken)
$response

This change removes the assignment, results will be immediately written to the output pipeline. A secondary benefit is that this version should perform better as it loses the expensive array creation / copy operation hidden behind +=.

[int]$i = 1
do {
    $result = $request.Execute()
    $result.Files | Select-Object @{N = 'User';E = {$User}},*
    if ($result.NextPageToken) {
        $request.PageToken = $result.NextPageToken
    }
    [int]$retrieved = ($i + $result.Files.Count) - 1
    Write-Verbose "Retrieved $retrieved Files..."
    [int]$i = $i + $result.Files.Count
}
until (!$result.NextPageToken)

Memory will only be consumed by this command for each page, or if the requestor performs their own assignment.

Are you happy with the change? Would you like a pull request?

@scrthq
Copy link
Member

scrthq commented May 2, 2018 via email

@scrthq scrthq self-assigned this May 2, 2018
@scrthq scrthq closed this as completed in #41 May 4, 2018
scrthq added a commit that referenced this issue May 4, 2018
## 2.5.3

* Fixed/Added: Specific domain support for listing users with `Get-GSUser -Filter $filter -Domain domain2.com` to allow customers with multiple domains to only list users for a specific domain instead of just the entire customer or domain saved in the config. (Resolve [Issue #32](#32))
* Added: Better verbose output in when listing users
* Fixed: Performance increase in `Get-GSDriveFileList` but returning DriveFile objects as it iterates through each page instead of storing in an array and returning the array at the end (Resolve [Issue #38](#38))
@scrthq
Copy link
Member

scrthq commented May 4, 2018

@indented-automation added the changes and pushed it out in v2.5.3! Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants