Skip to content

Commit

Permalink
Just a little cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottArbeit committed Jan 1, 2025
1 parent 0272762 commit f9f32cc
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 48 deletions.
5 changes: 3 additions & 2 deletions src/Grace.Actors/Branch.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ open Microsoft.Extensions.Logging
open System
open System.Collections.Generic
open System.Diagnostics
open System.Linq
open System.Runtime.Serialization
open System.Text
open System.Threading.Tasks
Expand Down Expand Up @@ -299,7 +300,7 @@ module Branch =
member private this.ApplyEvent branchEvent =
task {
try
if branchEvents.Count = 0 then do! this.OnFirstWrite()
if branchEvents |> Seq.isEmpty then do! this.OnFirstWrite()

// Update the branchDto with the event.
let! updatedBranchDto = branchDto |> updateDto branchEvent this.correlationId
Expand Down Expand Up @@ -505,7 +506,7 @@ module Branch =
logToConsole
$"In BranchActor.Handle.processCommand: Error rebasing on referenceId: {basedOn}. promotionDto: {serialize promotionDto}"

memoryCache.CreateBranchNameEntry branchName branchId
memoryCache.CreateBranchNameEntry $"{repositoryId}" branchName branchId

return Ok(Created(branchId, branchName, parentBranchId, basedOn, repositoryId, branchPermissions))
| BranchCommand.Rebase referenceId ->
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Actors/DirectoryAppearance.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module DirectoryAppearance =
let wasRemoved = dto.Appearances.Remove(appearance)

if wasRemoved then
if dto.Appearances.Count = 0 then
if dto.Appearances |> Seq.isEmpty then
let! deleteSucceeded = Storage.DeleteState stateManager dtoStateName

if deleteSucceeded then
Expand Down
8 changes: 4 additions & 4 deletions src/Grace.Actors/Extensions/MemoryCache.Extensions.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ module MemoryCache =


/// Create a new entry in MemoryCache to link a BranchName with a BranchId.
member this.CreateBranchNameEntry (branchName: string) (branchId: BranchId) =
this.CreateWithDefaultExpirationTime $"{branchNamePrefix}:{branchName}" branchId
member this.CreateBranchNameEntry (repositoryId: string) (branchName: string) (branchId: BranchId) =
this.CreateWithDefaultExpirationTime $"{branchNamePrefix}:{repositoryId}-{branchName}" branchId

/// Check if we have an entry in MemoryCache for a BranchName, and return the BranchId if we have it.
member this.GetBranchNameEntry(branchName: string) = this.GetFromCache<Guid> $"{branchNamePrefix}:{branchName}"
member this.GetBranchNameEntry (repositoryId: string) (branchName: string) = this.GetFromCache<Guid> $"{branchNamePrefix}:{repositoryId}-{branchName}"

/// Remove an entry in MemoryCache for a BranchName.
member this.RemoveBranchNameEntry(branchName: string) = this.Remove($"{branchNamePrefix}:{branchName}")
member this.RemoveBranchNameEntry (repositoryId: string) (branchName: string) = this.Remove($"{branchNamePrefix}:{repositoryId}-{branchName}")


/// Create a new entry in MemoryCache to store the current thread count information.
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Actors/FileAppearance.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module FileAppearance =
let wasRemoved = dto.Appearances.Remove(appearance)

if wasRemoved then
if dto.Appearances.Count = 0 then
if dto.Appearances |> Seq.isEmpty then
// TODO: Delete the file from storage
do! stateManager.RemoveStateAsync(dtoStateName)
else
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 @@ -183,7 +183,7 @@ module Organization =
try
let! organizationEvents = this.OrganizationEvents()

if organizationEvents.Count = 0 then do! this.OnFirstWrite()
if organizationEvents |> Seq.isEmpty then do! this.OnFirstWrite()

organizationEvents.Add(organizationEvent)

Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Actors/Owner.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ module Owner =
try
let! ownerEvents = this.OwnerEvents()

if ownerEvents.Count = 0 then this.OnFirstWrite()
if ownerEvents |> Seq.isEmpty then this.OnFirstWrite()

ownerEvents.Add(ownerEvent)

Expand Down
15 changes: 8 additions & 7 deletions src/Grace.Actors/Services.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ module Services =
return None
else
// Check if we have an active BranchName actor with a cached result.
match memoryCache.GetBranchNameEntry branchName with
match (memoryCache.GetBranchNameEntry repositoryId branchName) with
| Some branchGuid ->
if branchGuid.Equals(Constants.MemoryCache.EntityDoesNotExist) then
// We have already checked and the branch does not exist.
Expand All @@ -661,7 +661,7 @@ module Services =
match! branchNameActorProxy.GetBranchId correlationId with
| Some branchId ->
// Add this BranchName and BranchId to the MemoryCache.
memoryCache.CreateBranchNameEntry branchName branchId
memoryCache.CreateBranchNameEntry repositoryId branchName branchId
memoryCache.CreateBranchIdEntry branchId MemoryCache.ExistsValue
return Some $"{branchId}"
| None ->
Expand Down Expand Up @@ -698,7 +698,7 @@ module Services =
branchGuid <- Guid.Parse(branchId)

// Add this BranchName and BranchId to the MemoryCache.
memoryCache.CreateBranchNameEntry branchName branchGuid
memoryCache.CreateBranchNameEntry repositoryId branchName branchGuid
memoryCache.CreateBranchIdEntry branchGuid MemoryCache.ExistsValue

// Set the BranchId in the BranchName actor.
Expand Down Expand Up @@ -1092,10 +1092,11 @@ module Services =
| Reference.ReferenceEventType.Created refDto -> references.Add(refDto)
| _ -> ())

Activity.Current
.SetTag("indexMetrics", $"{indexMetrics.Remove(indexMetrics.Length - 2, 2)}")
.SetTag("requestCharge", $"{requestCharge.Remove(requestCharge.Length - 2, 2)}")
|> ignore
if indexMetrics.Length >= 2 then
Activity.Current
.SetTag("indexMetrics", $"{indexMetrics.Remove(indexMetrics.Length - 2, 2)}")
.SetTag("requestCharge", $"{requestCharge.Remove(requestCharge.Length - 2, 2)}")
|> ignore
finally
stringBuilderPool.Return(indexMetrics)
stringBuilderPool.Return(requestCharge)
Expand Down
1 change: 0 additions & 1 deletion src/Grace.CLI/Command/Branch.CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,6 @@ module Branch =

if currentBranch.SaveEnabled then
let! (updatedGraceStatus, newVersions) = getNewGraceStatusAndDirectoryVersions previousGraceStatus differences

newGraceStatus <- updatedGraceStatus
newDirectoryVersions <- newVersions

Expand Down
8 changes: 4 additions & 4 deletions src/Grace.CLI/Command/Maintenance.CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ module Maintenance =
))
)

if errors.Count = 0 then
if errors |> Seq.isEmpty then
if parseResult |> verbose then
logToAnsiConsole Colors.Verbose "All files uploaded successfully."

Expand Down Expand Up @@ -502,7 +502,7 @@ module Maintenance =
))
)

if errors.Count = 0 then
if errors |> Seq.isEmpty then
()
else
AnsiConsole.MarkupLine($"{errors.Count} errors occurred.")
Expand Down Expand Up @@ -716,7 +716,7 @@ module Maintenance =
))
)

if errors.Count = 0 then
if errors |> Seq.isEmpty then
if parseResult |> verbose then
logToAnsiConsole Colors.Verbose "All files uploaded successfully."

Expand Down Expand Up @@ -902,7 +902,7 @@ module Maintenance =
))
)

if errors.Count = 0 then
if errors |> Seq.isEmpty then
()
else
AnsiConsole.MarkupLine($"{errors.Count} errors occurred.")
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.CLI/Command/Repository.CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ module Repository =
)

// Print out any errors that occurred.
if errors.Count = 0 then
if errors |> Seq.isEmpty then
()
else
AnsiConsole.MarkupLine($"{errors.Count} errors occurred.")
Expand Down
14 changes: 7 additions & 7 deletions src/Grace.CLI/Command/Services.CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,22 @@ module Services =
/// Serializes an object of type 'T to the specified file path using MessagePack.
let serializeMessagePack<'T> (filePath: string) (data: 'T) =
task {
let startInstant = getCurrentInstant ()
//let startInstant = getCurrentInstant ()
use fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize = 65536, useAsync = true)
do! MessagePackSerializer.SerializeAsync(fileStream, data, messagePackSerializerOptions)
let duration = $"{(getCurrentInstant () - startInstant).TotalSeconds:F3}"
logToAnsiConsole Colors.Important $"Serialized file {filePath}; compressed length: {fileStream.Length}; time elapsed: {duration}s."
//let duration = $"{(getCurrentInstant () - startInstant).TotalSeconds:F3}"
//logToAnsiConsole Colors.Important $"Serialized file {filePath}; compressed length: {fileStream.Length}; time elapsed: {duration}s."
}
:> Task

/// Deserializes an object of type 'T from the specified file path using MessagePack.
let deserializeMessagePack<'T> (filePath: string) =
task {
let startInstant = getCurrentInstant ()
//let startInstant = getCurrentInstant ()
use fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize = 65536, useAsync = true)
let! returnValue = MessagePackSerializer.DeserializeAsync<'T>(fileStream, messagePackSerializerOptions)
let duration = $"{(getCurrentInstant () - startInstant).TotalSeconds:F3}"
logToAnsiConsole Colors.Important $"Deserialized file {filePath}; compressed length: {fileStream.Length}; time elapsed: {duration}s."
//let duration = $"{(getCurrentInstant () - startInstant).TotalSeconds:F3}"
//logToAnsiConsole Colors.Important $"Deserialized file {filePath}; compressed length: {fileStream.Length}; time elapsed: {duration}s."
return returnValue
}

Expand Down Expand Up @@ -713,7 +713,7 @@ module Services =
))
)

if errors.Count = 0 then
if errors |> Seq.isEmpty then
return Ok(GraceReturnValue.Create true parameters.CorrelationId)
else
// use Seq.fold to create a single error message from the ConcurrentQueue<GraceError>
Expand Down
4 changes: 2 additions & 2 deletions src/Grace.CLI/Command/Watch.CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module Watch =
.ToList()

let message =
if fileDifferences.Count = 0 then
if fileDifferences |> Seq.isEmpty then
String.Empty
else
let sb = stringBuilderPool.Get()
Expand Down Expand Up @@ -516,7 +516,7 @@ module Watch =
logToAnsiConsole Colors.Verbose $"Scanning for differences."
let! differences = scanForDifferences graceStatus // <--- This always finds the directories with updated write times, but we never update GraceStatus below..

if differences.Count = 0 then
if differences |> Seq.isEmpty then
logToAnsiConsole Colors.Verbose $"Already up-to-date."
else
logToAnsiConsole Colors.Verbose $"Found {differences.Count} differences."
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.CLI/Program.CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module GraceCommand =

/// If the command has no arguments - the user just typed `grace` - then we'll show the help screen and avoid showing an error message by adding a token that asks for help.
let noErrorIfNoArgumentsMiddleware (context: InvocationContext) =
if context.ParseResult.Tokens.Count = 0 then
if context.ParseResult.Tokens |> Seq.isEmpty then
context.ParseResult <- context.Parser.Parse(helpOptions[0])

let decideIfThisInstanceShouldBeCaseInsensitiveMiddleware (context: InvocationContext) =
Expand Down
15 changes: 2 additions & 13 deletions src/Grace.Server/ApplicationContext.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ module ApplicationContext =
let version = assembly.GetName().Version
let fileInfo = FileInfo(assembly.Location)

logToConsole $"In setConfiguration: isNull(config): {isNull (config)}."
logToConsole $"Grace Server version: {version}; build time (UTC): {fileInfo.LastWriteTimeUtc}."

configuration <- config
Expand Down Expand Up @@ -117,16 +116,6 @@ module ApplicationContext =
task {
let mutable isReady = false

let mutable workerThreads = 0
let mutable completionPortThreads = 0
ThreadPool.GetMaxThreads(&workerThreads, &completionPortThreads)
logToConsole $"Initial ThreadPool.GetMaxThreads: workerThreads: {workerThreads}; completionPortThreads: {completionPortThreads}."
ThreadPool.GetAvailableThreads(&workerThreads, &completionPortThreads)
logToConsole $"Initial ThreadPool.GetAvailableThreads: workerThreads: {workerThreads}; completionPortThreads: {completionPortThreads}."

//let threadPoolSet = ThreadPool.SetMinThreads(25, 1000)
//if not <| threadPoolSet then logToConsole "Could not set ThreadPool.MinThreads."

// Wait for the Dapr gRPC port to be ready.
logToConsole
$"""----------------------------------------------------------------------------------------------
Expand All @@ -136,8 +125,8 @@ module ApplicationContext =
talk to Dapr, so Grace Server will wait for {secondsToWaitForDaprToBeReady} seconds for Dapr to be ready.
If no connection is made, that almost always means that something happened trying
to start the Dapr sidecar, and Kubernetes is going to restart it. If that happens,
Grace Server also will exit and allow Kubernetes to restart it; by the time Grace Server
restarts, the Dapr sidecar will be up and running, and we should connect right away.
Grace Server will exit to allow Kubernetes to restart it; by the time Grace Server
restarts, the Dapr sidecar is usually up and running, and we should connect right away.
-----------------------------------------------------------------------------------------------"""

let mutable gRPCPort: int = 50001 // This is Dapr's default gRPC port.
Expand Down
4 changes: 2 additions & 2 deletions src/Grace.Server/Storage.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ module Storage =

let! failed = deleteAllFromCosmosDb ()

if failed.Count = 0 then
if failed |> Seq.isEmpty then
log.LogWarning("{CurrentInstant} Succeeded deleting all rows from CosmosDB.", getCurrentInstantExtended ())

return!
Expand Down Expand Up @@ -249,7 +249,7 @@ module Storage =

let! failed = deleteAllRemindersFromCosmosDb ()

if failed.Count = 0 then
if failed |> Seq.isEmpty then
log.LogWarning("{CurrentInstant} Succeeded deleting all reminders from CosmosDB.", getCurrentInstantExtended ())

return!
Expand Down

0 comments on commit f9f32cc

Please sign in to comment.