SCRT-HQ / PSGSuite

Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
https://psgsuite.io/
Apache License 2.0
235 stars 67 forks source link

add a -First option to Get-GSActivityReport #195

Closed WJurecki closed 5 years ago

WJurecki commented 5 years ago

When utilizing Get-GSActivityReport I would like to be able to limit the result set to a specified limit.

While simply using Get-GSActivityReport | Select-Object -First 50, for example, would limit the results to 50 items as desired, it requires all of the overhead of returning all results and then only selecting the first 50. By adding a -First option to Get-GSActivityReport the code could stop retrieving additional pages of results once the specified number has been received, thus reducing the time to obtain a final result set.

If, for example, I only wanted the first 50 objects I would simply use Get-GSActivityReport -First 50 -PageSize 50 which would return the entire set in one round-trip. If I only wanted to detect if ANY activity had happened I could use Get-GSActivityReport -First 1 -PageSize 1 which would result in one round-trip with the smallest possible result set.

scrthq commented 5 years ago

Hey @WJurecki - Great idea! Checking it out!

scrthq commented 5 years ago

@WJurecki - Since this is pretty applicable to any of the other List functions, I POC'd it with Get-GSTeamDrive and it's working well. I opted for a parameter named Limit instead of First, but will add First as an alias to that parameter where applicable:

image

Green circled blocks shows the reduction of the page size when the next page is calculated to exceed the desired limit so that only the exact count desired are returned.

Blue circled blocks show the reduction of the page size when the first page is calculated to exceed the desired limit.

scrthq commented 5 years ago

@WJurecki - Working well! Using your initial examples, for reference:

image

scrthq commented 5 years ago

Bonus guardrails:

image

scrthq commented 5 years ago

Sneak peak at the changelog so far for 2.28.0 with this request's additions highlighted 😃

image

scrthq commented 5 years ago

Hey @WJurecki - This has been deployed in v2.28.0! Let me know if all is well or if you are seeing any issues!

WJurecki commented 5 years ago

@scrthq - Looks great. I've tried it a few times and looks to work well. I'll let you know if I run into any problems. Thanks again

scrthq commented 5 years ago

Perfect! Thanks, @WJurecki !