Skip to content

Commit

Permalink
Converted validations to ValueTask<'T>.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottArbeit committed Dec 1, 2023
1 parent 1221353 commit fca24a0
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 136 deletions.
3 changes: 3 additions & 0 deletions src/Create-Grace-Objects.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ $startTime = Get-Date

grace owner create --output Verbose --ownerName $ownerNameOriginal --ownerId $ownerId --doNotSwitch
grace owner set-name --output Verbose --ownerId $ownerId --newName $ownerName
grace owner get --output Verbose --ownerId $ownerId
grace org create --output Verbose --ownerId $ownerId --organizationName $orgNameOriginal --organizationId $organizationId --doNotSwitch
grace org set-name --output Verbose --ownerId $ownerId --organizationId $organizationId --newName $orgName
grace org get --output Verbose --ownerId $ownerId --organizationId $organizationId
grace repo create --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryName $repoNameOriginal --repositoryId $repoId --doNotSwitch
grace repo set-name --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryId $repoId --newName $repoName
#grace repo get --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryId $repoId
grace branch create --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryId $repoId --branchId $branchId --branchName $branchName --parentBranchName main --doNotSwitch

$words = "Sit fusce at sociosqu eros bibendum aliquet cursus ante non facilisis tempor Scelerisque arcu potenti feugiat fermentum viverra et litora facilisis vestibulum sit aliquam quisque sagittis ut Ultricies nisi urna cursus tellus tempor vivamus nec Dictumst tristique porta vel cubilia mollis Tempus nullam laoreet sit vestibulum etiam in volutpat dui class netus morbi Duis facilisis at aliquet fusce nisi Nulla arcu molestie mauris integer aenean ligula curabitur dui sociosqu suspendisse mi fringilla faucibus Rhoncus habitasse massa amet ipsum ligula quisque Quisque fames bibendum eu ullamcorper pulvinar in aenean hendrerit Augue tristique aenean amet auctor curabitur congue placerat aenean posuere porttitor pulvinar lectus Mattis aenean elit condimentum nam iaculis ante felis sollicitudin Risus viverra ornare curabitur sem massa nibh vulputate senectus dictum vitae leo varius dictumst tristique Ultrices ut blandit adipiscing dictumst sagittis elementum urna Vel feugiat consectetur malesuada nibh turpis odio convallis molestie vulputate magna venenatis lacinia Suscipit consequat lectus nullam suspendisse aliquam sed venenatis Feugiat vehicula iaculis donec aenean Volutpat amet feugiat fringilla bibendum scelerisque fermentum pellentesque hendrerit dapibus primis eu ipsum proin mauris Amet magna non mattis dictum risus sit Luctus hendrerit in integer euismod sapien aenean vel maecenas venenatis lorem cubilia taciti Id mauris dictum aenean leo quisque auctor sagittis nisl rutrum at Iaculis luctus orci egestas metus commodo praesent sodales nam quis conubia cras sagittis vestibulum Viverra justo cursus tempor fringilla egestas Potenti aliquam quisque tincidunt pellentesque Lacinia eu convallis quis risus accumsan Augue adipiscing orci massa lorem curabitur eleifend tincidunt justo varius vulputate Mollis aenean est pulvinar proin in donec bibendum dolor quis sociosqu mattis mi Euismod urna leo mollis potenti fames mattis ultrices diam Vivamus sit mattis vehicula viverra mi imperdiet Adipiscing est vehicula scelerisque velit Malesuada integer quisque fusce quis mollis eros Leo nec tellus curabitur ornare amet quisque fusce habitasse morbi Sem lacinia eu aenean pretium curae dolor cubilia faucibus purus Sollicitudin nisl tempus auctor etiam felis urna consectetur donec dui Posuere elit orci lobortis magna Enim at pellentesque ac taciti convallis sapien ad elit Integer potenti malesuada lacinia fames euismod amet purus justo sociosqu dolor cras tempus dictumst Dictumst adipiscing quisque sapien pharetra pretium aliquam nunc ipsum varius mi justo aenean mattis Aenean conubia felis inceptos nulla ante sociosqu libero non imperdiet Nunc feugiat sodales commodo interdum rhoncus nulla aliquet cras sociosqu eros sed Vivamus varius sapien sollicitudin curabitur class aenean tempus tempor magna donec bibendum nulla morbi semper Praesent inceptos etiam tempus in Varius hac et feugiat nullam dictum vivamus adipiscing ut in eros nulla molestie ante Interdum dictum volutpat accumsan posuere quis amet curae nostra purus fusce nisl lacus Aenean erat suscipit urna ante In ad varius interdum porta at pulvinar aptent enim nam sit ultrices hendrerit Vitae rhoncus consequat non metus nullam augue Massa vestibulum dapibus lectus nibh at tortor ullamcorper mattis rutrum pellentesque aliquam adipiscing porttitor".Split()
Expand Down
5 changes: 1 addition & 4 deletions src/Grace.Actors/Branch.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ module Branch =

interface IBranchActor with
member this.Exists() =
if branchDto.BranchId = BranchDto.Default.BranchId then
false |> returnTask
else
true |> returnTask
not <| (branchDto.BranchId = BranchDto.Default.BranchId) |> returnTask

member this.Handle (command: BranchCommand) (metadata: EventMetadata) =
let isValid (command: BranchCommand) (metadata: EventMetadata) =
Expand Down
4 changes: 2 additions & 2 deletions src/Grace.Actors/Diff.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ module Diff =

member private this.GetDiffSimple() =
if diffDto.DirectoryId1 = DiffDto.Default.DirectoryId1 then
None |> returnTask
None |> returnValueTask
else
Some diffDto |> returnTask
Some diffDto |> returnValueTask

interface IDiffActor with
member this.Populate() =
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Actors/DirectoryVersion.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module DirectoryVersion =

member this.Delete(correlationId) = GraceResult.Error (GraceError.Create "Not implemented" correlationId) |> returnTask

member this.Get() = directoryVersion |> returnTask
member this.Get() = directoryVersion |> returnTask

member this.GetCreatedAt() = directoryVersion.CreatedAt |> returnTask

Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Actors/Organization.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ module Organization =
// Mark the actor as disposed, in case someone tries to use it before Dapr GC's it.
isDisposed <- true

log.LogInformation("{currentInstant}: Physically deleted state for organization; OrganizationId: {organizationId}; OrganizationName: {organizationName}; OwnerId: {ownerId}; deletedDtoState: {deletedDtoState}; deletedEventsState: {deletedEventsState}.",
log.LogInformation("{currentInstant}: Deleted physical state for organization; OrganizationId: {organizationId}; OrganizationName: {organizationName}; OwnerId: {ownerId}; deletedDtoState: {deletedDtoState}; deletedEventsState: {deletedEventsState}.",
getCurrentInstantExtended(), organizationDto.OrganizationId, organizationDto.OrganizationName, organizationDto.OwnerId, deletedDtoState, deletedEventsState)

// Set all values to default.
Expand Down
30 changes: 15 additions & 15 deletions src/Grace.Server/Branch.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ open System.Threading.Tasks

module Branch =

type Validations<'T when 'T :> BranchParameters> = 'T -> HttpContext -> Task<Result<unit, BranchError>> array
type Validations<'T when 'T :> BranchParameters> = 'T -> HttpContext -> ValueTask<Result<unit, BranchError>> array

let activitySource = new ActivitySource("Branch")

Expand All @@ -56,7 +56,7 @@ module Branch =
String.isValidGraceName parameters.BranchName InvalidBranchName
Input.eitherIdOrNameMustBeProvided parameters.BranchId parameters.BranchName EitherBranchIdOrBranchNameRequired |]

let processCommand<'T when 'T :> BranchParameters> (context: HttpContext) (validations: Validations<'T>) (command: 'T -> Task<BranchCommand>) =
let processCommand<'T when 'T :> BranchParameters> (context: HttpContext) (validations: Validations<'T>) (command: 'T -> ValueTask<BranchCommand>) =
task {
try
let commandName = context.Items["Command"] :?> string
Expand Down Expand Up @@ -173,7 +173,7 @@ module Branch =
ReferenceId.Empty, // This is fucked.
Guid.Parse(parameters.RepositoryId),
parameters.InitialPermissions)
}
} |> ValueTask<BranchCommand>

context.Items.Add("Command", nameof(Create))
return! processCommand context validations command
Expand All @@ -194,7 +194,7 @@ module Branch =
Branch.branchAllowsReferenceType parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName ReferenceType.Commit CommitIsDisabled |]

let command (parameters: RebaseParameters) =
Rebase(parameters.BasedOn) |> returnTask
Rebase(parameters.BasedOn) |> returnValueTask

context.Items.Add("Command", nameof(Rebase))
return! processCommand context validations command
Expand All @@ -216,7 +216,7 @@ module Branch =
Branch.branchAllowsReferenceType parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName ReferenceType.Promotion PromotionIsDisabled |]

let command (parameters: CreateReferenceParameters) =
Promote(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnTask
Promote(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnValueTask

context.Items.Add("Command", nameof(Promote))
return! processCommand context validations command
Expand All @@ -238,7 +238,7 @@ module Branch =
Branch.branchAllowsReferenceType parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName ReferenceType.Commit CommitIsDisabled |]

let command (parameters: CreateReferenceParameters) =
BranchCommand.Commit(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnTask
BranchCommand.Commit(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnValueTask

context.Items.Add("Command", nameof(Commit))
return! processCommand context validations command
Expand All @@ -260,7 +260,7 @@ module Branch =
Branch.branchAllowsReferenceType parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName ReferenceType.Checkpoint CheckpointIsDisabled |]

let command (parameters: CreateReferenceParameters) =
BranchCommand.Checkpoint(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnTask
BranchCommand.Checkpoint(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnValueTask

context.Items.Add("Command", nameof(Checkpoint))
return! processCommand context validations command
Expand All @@ -282,7 +282,7 @@ module Branch =
Branch.branchAllowsReferenceType parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName ReferenceType.Save SaveIsDisabled |]

let command (parameters: CreateReferenceParameters) =
BranchCommand.Save(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnTask
BranchCommand.Save(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnValueTask

context.Items.Add("Command", nameof(Save))
return! processCommand context validations command
Expand All @@ -304,7 +304,7 @@ module Branch =
Branch.branchAllowsReferenceType parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName ReferenceType.Tag TagIsDisabled |]

let command (parameters: CreateReferenceParameters) =
BranchCommand.Tag(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnTask
BranchCommand.Tag(parameters.DirectoryId, parameters.Sha256Hash, ReferenceText parameters.Message) |> returnValueTask

context.Items.Add("Command", nameof(Tag))
return! processCommand context validations command
Expand All @@ -324,7 +324,7 @@ module Branch =
Branch.branchExists parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName BranchDoesNotExist |]

let command (parameters: EnableFeatureParameters) =
EnablePromotion(parameters.Enabled) |> returnTask
EnablePromotion(parameters.Enabled) |> returnValueTask

context.Items.Add("Command", nameof(EnablePromotion))
return! processCommand context validations command
Expand All @@ -344,7 +344,7 @@ module Branch =
Branch.branchExists parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName BranchDoesNotExist |]

let command (parameters: EnableFeatureParameters) =
EnableCommit(parameters.Enabled) |> returnTask
EnableCommit(parameters.Enabled) |> returnValueTask

context.Items.Add("Command", nameof(EnableCommit))
return! processCommand context validations command
Expand All @@ -364,7 +364,7 @@ module Branch =
Branch.branchExists parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName BranchDoesNotExist |]

let command (parameters: EnableFeatureParameters) =
EnableCheckpoint(parameters.Enabled) |> returnTask
EnableCheckpoint(parameters.Enabled) |> returnValueTask

context.Items.Add("Command", nameof(EnableCheckpoint))
return! processCommand context validations command
Expand All @@ -384,7 +384,7 @@ module Branch =
Branch.branchExists parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName ParentBranchDoesNotExist |]

let command (parameters: EnableFeatureParameters) =
EnableSave(parameters.Enabled) |> returnTask
EnableSave(parameters.Enabled) |> returnValueTask

context.Items.Add("Command", nameof(EnableSave))
return! processCommand context validations command
Expand All @@ -404,7 +404,7 @@ module Branch =
Branch.branchExists parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName BranchDoesNotExist |]

let command (parameters: EnableFeatureParameters) =
EnableTag(parameters.Enabled) |> returnTask
EnableTag(parameters.Enabled) |> returnValueTask

context.Items.Add("Command", nameof(EnableTag))
return! processCommand context validations command
Expand All @@ -424,7 +424,7 @@ module Branch =
Branch.branchExists parameters.OwnerId parameters.OwnerName parameters.OrganizationId parameters.OrganizationName parameters.RepositoryId parameters.RepositoryName parameters.BranchId parameters.BranchName BranchDoesNotExist |]

let command (parameters: DeleteBranchParameters) =
DeleteLogical (parameters.Force, parameters.DeleteReason) |> returnTask
DeleteLogical (parameters.Force, parameters.DeleteReason) |> returnValueTask

context.Items.Add("Command", nameof(DeleteLogical))
return! processCommand context validations command
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Server/Diff.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open System.Threading.Tasks
open System.Text.Json

module Diff =
type Validations<'T when 'T :> DiffParameters> = 'T -> HttpContext -> Task<Result<unit, DiffError>> array
type Validations<'T when 'T :> DiffParameters> = 'T -> HttpContext -> ValueTask<Result<unit, DiffError>> array

let activitySource = new ActivitySource("Repository")

Expand Down
4 changes: 2 additions & 2 deletions src/Grace.Server/Directory.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open System.Threading.Tasks

module DirectoryVersion =

type Validations<'T when 'T :> DirectoryParameters> = 'T -> HttpContext -> Task<Result<unit, DirectoryError>> array
type Validations<'T when 'T :> DirectoryParameters> = 'T -> HttpContext -> ValueTask<Result<unit, DirectoryError>> array
//type QueryResult<'T, 'U when 'T :> DirectoryParameters> = 'T -> int -> IDirectoryVersionActor ->Task<'U>

let activitySource = new ActivitySource("Branch")
Expand Down Expand Up @@ -194,7 +194,7 @@ module DirectoryVersion =
fun (next: HttpFunc) (context: HttpContext) ->
task {
let validations (parameters: SaveDirectoryVersionsParameters) (context: HttpContext) =
let mutable allValidations: Task<Result<unit, DirectoryError>> array = Array.Empty()
let mutable allValidations: ValueTask<Result<unit, DirectoryError>> array = Array.Empty()
for directoryVersion in parameters.DirectoryVersions do
let validations =
[| Guid.isValidAndNotEmpty $"{directoryVersion.DirectoryId}" DirectoryError.InvalidDirectoryId
Expand Down
Loading

0 comments on commit fca24a0

Please sign in to comment.