sfpowerscripts icon indicating copy to clipboard operation
sfpowerscripts copied to clipboard

Optimise number of queries for resolving package versions

Open aly76 opened this issue 3 years ago • 2 comments

During Build, a single Tooling API query is made for the first occurrence of each package dependency version, to resolve the LATEST keyword. This could be further optimised by sending only a single query with all the Package2 Id's aggregated and then sorting the response by package and descending semantic version.

Pro's:

  • 1 query, instead of 'n' unique package dependencies

Cons:

  • Limit of 50,000 records returned per SOQL query
  • Additional computation on client-side for sorting response by package and version number
  • Cannot specify MajorVersion, MinorVersion, PatchVersion or BuildNumber in SOQL query, causing more records to be returned and additional sorting computation

aly76 avatar Jun 17 '22 02:06 aly76

@rody Can you weigh in your thoughts here

azlam-abdulsalam avatar Jun 17 '22 02:06 azlam-abdulsalam

something like:

SELECT Package2.Name, MajorVersion, MinorVersion, PatchVersion, max(BuildNumber)
FROM Package2Version
WHERE (Package2.Name = 'logging' AND MajorVersion=0 AND MinorVersion=1 AND PatchVersion=0)
 OR (Package2.Name = 'async-framework' AND MajorVersion=0 AND MinorVersion=1 AND PacthVersion=0)
GROUP BY Package2Id, Package2.Name, MajorVersion, MinorVersion, PatchVersion

with a dynamic WHERE section (note that you are limited in the size of that section)

I'm assuming that we are trying to find the latest build of a declared dependency, not the absolute latest package version (i.e. MajorVersion and MinorVersion are given in sfdx-project.json)

edit: adding PatchVersion field

rody avatar Jun 17 '22 04:06 rody