Skip to content

Commit

Permalink
fix: enables rebuilding of projections that don't have a live version
Browse files Browse the repository at this point in the history
  • Loading branch information
ethno2405 committed Jun 16, 2022
1 parent 6744357 commit 943701d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ public void Replay(string hash, IProjectionVersioningPolicy policy)
}
}

public void Rebuild(string hash)
public void Rebuild(string hash, IProjectionVersioningPolicy policy)
{
ProjectionVersion currentLiveVersion = state.Versions.GetLive();

if (CanRebuild(currentLiveVersion))
if (CanRebuild(hash))
{
ProjectionVersion currentLiveVersion = state.Versions.GetNext(policy, hash);
var timebox = GetVersionRequestTimebox(hash);
RequestVersion(state.Id, currentLiveVersion.WithStatus(ProjectionStatus.Rebuilding), timebox);
}
Expand Down Expand Up @@ -114,12 +113,13 @@ private bool CanReplay(string hash, IProjectionVersioningPolicy policy)
return (doesntHaveBuildingVersion && isVersionable) || (doesntHaveBuildingVersion && isVersionable == false && isNewHashTheLiveOne == false);
}

private bool CanRebuild(ProjectionVersion currentLiveVersion)
private bool CanRebuild(string hash)
{
ProjectionVersion currentLiveVersion = state.Versions.GetLive();
if (currentLiveVersion is null)
return false;
return true;

bool hashMatchesCurrentLiveVersion = currentLiveVersion.Hash.Equals(currentLiveVersion.Hash);
bool hashMatchesCurrentLiveVersion = currentLiveVersion.Hash.Equals(hash);
bool hasRebuildingVersion = state.Versions.HasRebuildingVersion();

return hashMatchesCurrentLiveVersion && hasRebuildingVersion == false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Task HandleAsync(ReplayProjection command)

public Task HandleAsync(RebuildProjectionCommand command)
{
return UpdateAsync(command.Id, ar => ar.Rebuild(command.Hash));
return UpdateAsync(command.Id, ar => ar.Rebuild(command.Hash, projectionVersioningPolicy));
}

public Task HandleAsync(FinalizeProjectionVersionRequest command)
Expand Down

0 comments on commit 943701d

Please sign in to comment.