Skip to content
This repository has been archived by the owner on Apr 4, 2020. It is now read-only.

Commit

Permalink
optimizing getrelease and getlatestrelease
Browse files Browse the repository at this point in the history
  • Loading branch information
p-ob committed Jan 27, 2016
1 parent fd68b0e commit 1cf90e3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Kraken/Services/OctopusProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,25 @@ public IEnumerable<ProjectResource> GetProjects(string nameFilter)

public ReleaseResource GetLastestRelease(string projectId)
{
return _octopusRepository.Releases.FindOne(r => r.ProjectId == projectId);
var project = GetProject(projectId);
var releases = _octopusRepository.Projects.GetReleases(project).Items;
return releases.FirstOrDefault();
}

public ReleaseResource GetLastDeployedRelease(string projectId, string environmentId)
{
var deployment = _octopusRepository.Deployments.FindOne(d => d.ProjectId == projectId && (string.IsNullOrEmpty(environmentId) || d.EnvironmentId == environmentId));
var project = GetProject(projectId);
var releases = _octopusRepository.Projects.GetReleases(project).Items;
DeploymentResource deployment;
foreach (var release in releases)
{
deployment =
_octopusRepository.Releases.GetDeployments(release)
.Items.FirstOrDefault(d => d.EnvironmentId == environmentId);

if (deployment != null) break;
}
deployment = _octopusRepository.Deployments.FindOne(d => d.ProjectId == projectId && (string.IsNullOrEmpty(environmentId) || d.EnvironmentId == environmentId));
return deployment != null ? _octopusRepository.Releases.Get(deployment.ReleaseId) : null;
}

Expand Down Expand Up @@ -120,11 +133,10 @@ public ReleaseResource CreateRelease(string projectId, string version, IEnumerab

public ReleaseResource CreateRelease(ReleaseResource release)
{
var checkRelease =
_octopusRepository.Releases.FindOne(
r => r.ProjectId == release.ProjectId && new Version(r.Version) <= new Version(release.Version));
var project = GetProject(release.ProjectId);
var checkRelease = _octopusRepository.Projects.GetReleaseByVersion(project, release.Version);

return checkRelease.Version == release.Version ? checkRelease : _octopusRepository.Releases.Create(release);
return checkRelease ?? _octopusRepository.Releases.Create(release);
}

private readonly OctopusRepository _octopusRepository;
Expand Down

0 comments on commit 1cf90e3

Please sign in to comment.