Is there a better way to optimize this code? Currently with only a few hundred releases in the system (Cloud) this code block takes over 30 seconds to complete. Using my original flow that used the repos instead of the client get the same thing would take minutes.
The intent is to get the most recent successful deployment of every project in every environment for a given tenantid, currently this does that except it gets all deployments not just the most recent. I cannot figure out how to do that in the get query.
C#
var space = await client.Repository.Spaces.FindOne(x => x.Id == spaceId);
var repos = client.ForSpace(space);
var envs = await repos.Environments.GetAll();
var tenant = await repos.Tenants.FindOne(x => x.Id == tenantId);
var root = await repos.LoadSpaceRootDocument();
//under 30 projects, no need to use get
var projects = await repos.Projects.FindMany(x => x.TenantedDeploymentMode != TenantedDeploymentMode.Untenanted && tenant.ProjectEnvironments.ContainsKey(x.Id) );
var deployments = await repos.Client.Get<ResourceCollection< DeploymentResource>>(root.Links[“Deployments”] + $"?take=100000&tenants={tenantId}");
var.releases = await repos.Client.Get<ResourceCollection< ReleaseResource>>(root.Links[“Releases”] + $"?take=100000&ids={deployments.Items.Select(x => x.ReleaseId).Aggregate((a,b) => a + “,” + b)}");
//no links available in root document for tasks.
var tasks = await repos.Tasks.FindMany(x => x.IsCompleted && x.FinishedSuccessfully && deployments.Items.Select(d => d.TaskId).Contains(x.Id));
Also this text editor does strang things when something is formatted like
<word< anotherword>> without the white space the inner <> is removed.