Skip to content

Commit

Permalink
Fixes from AI comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceredron committed Jan 15, 2025
1 parent baeefae commit 3318ea2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 11 additions & 16 deletions Test/Altinn.Correspondence.LoadTests.DatabasePopulater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ static async Task FillWithTestDataAsync(ApplicationDbContext applicationDbContex
for (int i = 0; i < threadCount; i++)
{
var freshConnection = new NpgsqlConnection(applicationDbContext.Database.GetConnectionString());
tasks.Add(RunPopulateQueryAsync(correspondenceCount, freshConnection));
tasks.Add(RunPopulateQueryAsync(correspondenceCount/threadCount, freshConnection));
}
if (correspondenceCount % threadCount != 0)
{
var freshConnection = new NpgsqlConnection(applicationDbContext.Database.GetConnectionString());
tasks.Add(RunPopulateQueryAsync(correspondenceCount % threadCount, freshConnection));
}

await Task.WhenAll(tasks);
Expand All @@ -223,8 +228,8 @@ static int GetThreadCount(int correspondenceCount)

private static string ReadFileContent(string path)
{
var fileStream = File.OpenRead(path);
var streamReader = new StreamReader(fileStream);
using var fileStream = File.OpenRead(path);
using var streamReader = new StreamReader(fileStream);
var fileContent = streamReader.ReadToEnd();
return fileContent;
}
Expand All @@ -233,20 +238,10 @@ private static async Task RunPopulateQueryAsync(int count, DbConnection dbConnec
{
if (dbConnection.State != System.Data.ConnectionState.Open)
await dbConnection.OpenAsync();
var command = dbConnection.CreateCommand();
using var command = dbConnection.CreateCommand();
command.CommandText = $"SELECT populate_test_database({count});";
await command.ExecuteNonQueryAsync();
dbConnection.Close();
dbConnection.Dispose();
}
}


/*
* Todo:
* Create resources with policies:
* medl-correspondence-1
* ...
* medl-correspondence-10
*
* Distribute 500 million correspondences on these
*
*/
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ begin
WHERE identifier != 'urn:altinn:organization:identifier-no:' || Sender."orgnumber_ak"
LIMIT 1
) R
RETURNING "Id", 'b2c6699b-b602-425d-a583-7138a8b7b7d5'::uuid AS "PartyUuid"
RETURNING "Id", gen_random_uuid()::uuid AS "PartyUuid"
)
INSERT INTO temp_correspondencebase ("Id", "PartyUuid")
SELECT "Id", "PartyUuid" FROM inserted_correspondences;
Expand Down

0 comments on commit 3318ea2

Please sign in to comment.