Optimise number of queries for resolving package versions
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,PatchVersionorBuildNumberin SOQL query, causing more records to be returned and additional sorting computation
@rody Can you weigh in your thoughts here
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