-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from NielsPilgaard/feature/blazor-server
Migrate to InteractiveServer + Blazor Web App Built-in Authentication
- Loading branch information
Showing
297 changed files
with
9,153 additions
and
7,156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 15 additions & 15 deletions
30
benchmarks/Jordnaer.Benchmarks/BenchmarkWebApplicationFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
using Jordnaer.Server.Database; | ||
using Jordnaer.Database; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
|
||
namespace Jordnaer.Server.Benchmarks; | ||
namespace Jordnaer.Benchmarks; | ||
|
||
public class BenchmarkWebApplicationFactory : WebApplicationFactory<Program> | ||
{ | ||
public BenchmarkWebApplicationFactory() | ||
{ | ||
Environment.SetEnvironmentVariable($"ConnectionStrings_{nameof(JordnaerDbContext)}", | ||
"Server=localhost;" + | ||
"Initial Catalog=jordnaer;" + | ||
"User Id=sa;" + | ||
"Password=6efe173b-3e33-4d6c-8f50-3e5f7cadd54c;" + | ||
"Persist Security Info=True;" + | ||
"MultipleActiveResultSets=False;" + | ||
"Encrypt=False;" + | ||
"TrustServerCertificate=True;" + | ||
"Connection Timeout=30;"); | ||
} | ||
public BenchmarkWebApplicationFactory() | ||
{ | ||
Environment.SetEnvironmentVariable($"ConnectionStrings_{nameof(JordnaerDbContext)}", | ||
"Server=localhost;" + | ||
"Initial Catalog=jordnaer;" + | ||
"User Id=sa;" + | ||
"Password=6efe173b-3e33-4d6c-8f50-3e5f7cadd54c;" + | ||
"Persist Security Info=True;" + | ||
"MultipleActiveResultSets=False;" + | ||
"Encrypt=False;" + | ||
"TrustServerCertificate=True;" + | ||
"Connection Timeout=30;"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Jordnaer.Server.Database; | ||
using Jordnaer.Database; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Jordnaer.Server.Benchmarks; | ||
namespace Jordnaer.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class RenderProfileBenchmark | ||
{ | ||
private string _userName = null!; | ||
private HttpClient _client = null!; | ||
private string _userName = null!; | ||
private HttpClient _client = null!; | ||
|
||
[GlobalSetup] | ||
public async Task GlobalSetupAsync() | ||
{ | ||
var factory = new BenchmarkWebApplicationFactory(); | ||
[GlobalSetup] | ||
public async Task GlobalSetupAsync() | ||
{ | ||
var factory = new BenchmarkWebApplicationFactory(); | ||
|
||
using var scope = factory.Services.CreateScope(); | ||
using var scope = factory.Services.CreateScope(); | ||
|
||
await using var context = scope.ServiceProvider.GetRequiredService<JordnaerDbContext>(); | ||
await using var context = scope.ServiceProvider.GetRequiredService<JordnaerDbContext>(); | ||
|
||
await context.Database.MigrateAsync(); | ||
await context.Database.MigrateAsync(); | ||
|
||
var categories = await context.InsertCategoriesAsync(); | ||
var categories = await context.InsertCategoriesAsync(); | ||
|
||
await context.InsertFakeUsersAsync(categories, 100); | ||
await context.InsertFakeUsersAsync(categories, 100); | ||
|
||
await context.SaveChangesAsync(); | ||
await context.SaveChangesAsync(); | ||
|
||
var user = await context.UserProfiles.FirstOrDefaultAsync(); | ||
_userName = user!.UserName!; | ||
var user = await context.UserProfiles.FirstOrDefaultAsync(); | ||
_userName = user!.UserName!; | ||
|
||
_client = factory.CreateClient(); | ||
} | ||
_client = factory.CreateClient(); | ||
} | ||
|
||
[Benchmark] | ||
public async Task RenderProfileAsync() => await _client.GetAsync($"/{_userName}"); | ||
[Benchmark] | ||
public async Task RenderProfileAsync() => await _client.GetAsync($"/{_userName}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
using System.Reflection; | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Jordnaer.Server.Benchmarks; | ||
namespace Jordnaer.Benchmarks; | ||
|
||
public class StartBenchmark | ||
{ | ||
public static void Main() => BenchmarkRunner.Run(Assembly.GetExecutingAssembly()); | ||
public static void Main() => BenchmarkRunner.Run(Assembly.GetExecutingAssembly()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,95 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Jordnaer.Client.Features.UserSearch; | ||
using Jordnaer.Server.Database; | ||
using Jordnaer.Database; | ||
using Jordnaer.Features.UserSearch; | ||
using Jordnaer.Shared; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Refit; | ||
|
||
namespace Jordnaer.Server.Benchmarks; | ||
namespace Jordnaer.Benchmarks; | ||
|
||
//TODO: This fails because the search endpoint requires auth and has rate limiting | ||
[MemoryDiagnoser] | ||
public class UserSearchBenchmark | ||
{ | ||
private IUserSearchClient _client = null!; | ||
private JordnaerDbContext _context = null!; | ||
private UserProfile _randomUser = null!; | ||
private List<Category> _categories = new(); | ||
|
||
[GlobalSetup] | ||
public async Task GlobalSetupAsync() | ||
{ | ||
var factory = new BenchmarkWebApplicationFactory(); | ||
factory.ClientOptions.AllowAutoRedirect = false; | ||
|
||
using var scope = factory.Services.CreateScope(); | ||
|
||
_context = scope.ServiceProvider.GetRequiredService<JordnaerDbContext>(); | ||
|
||
await _context.Database.MigrateAsync(); | ||
|
||
_categories = await _context.InsertCategoriesAsync(); | ||
|
||
await _context.InsertFakeUsersAsync(_categories); | ||
|
||
await _context.SaveChangesAsync(); | ||
|
||
var httpClient = factory.CreateClient(); | ||
|
||
_randomUser = (await _context.UserProfiles | ||
.Order() | ||
.Skip(Random.Shared.Next(0, 10000)) | ||
.Take(1) | ||
.FirstOrDefaultAsync())!; | ||
|
||
_client = RestService.For<IUserSearchClient>(httpClient); | ||
} | ||
|
||
[Benchmark] | ||
public async Task UserSearch_No_Filter() => | ||
await _client.GetUsers(new UserSearchFilter()); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_FirstName() => | ||
await _client.GetUsers(new UserSearchFilter { Name = _randomUser.FirstName }); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_LastName() => | ||
await _client.GetUsers(new UserSearchFilter { Name = _randomUser.LastName }); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_UserName() => | ||
await _client.GetUsers(new UserSearchFilter { Name = _randomUser.UserName }); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_Age_Of_Children() | ||
{ | ||
int minimumAge = Random.Shared.Next(0, 14); | ||
int maximumAge = Random.Shared.Next(minimumAge, 14); | ||
await _client.GetUsers(new UserSearchFilter { MinimumChildAge = minimumAge, MaximumChildAge = maximumAge }); | ||
} | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_Category() => | ||
await _client.GetUsers(new UserSearchFilter | ||
{ | ||
Categories = _categories | ||
.Select(category => category.Name) | ||
.Skip(Random.Shared.Next(0, _categories.Count)) | ||
.ToArray() | ||
}); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_Gender_Of_Children() | ||
{ | ||
var genders = Enum.GetValues<Gender>(); | ||
await _client.GetUsers(new UserSearchFilter { ChildGender = genders[Random.Shared.Next(0, genders.Length)] }); | ||
} | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_Address_Within_20_Kilometers() => | ||
await _client.GetUsers(new UserSearchFilter | ||
{ | ||
Location = $"{_randomUser.Address}, {_randomUser.ZipCode} {_randomUser.City}", | ||
WithinRadiusKilometers = 20 | ||
}); | ||
private IUserSearchService _service = null!; | ||
private JordnaerDbContext _context = null!; | ||
private UserProfile _randomUser = null!; | ||
private List<Category> _categories = []; | ||
|
||
[GlobalSetup] | ||
public async Task GlobalSetupAsync() | ||
{ | ||
var factory = new BenchmarkWebApplicationFactory(); | ||
factory.ClientOptions.AllowAutoRedirect = false; | ||
|
||
const int userCount = 10000; | ||
|
||
using var scope = factory.Services.CreateScope(); | ||
|
||
_context = scope.ServiceProvider.GetRequiredService<JordnaerDbContext>(); | ||
|
||
await _context.Database.MigrateAsync(); | ||
|
||
_categories = await _context.InsertCategoriesAsync(); | ||
|
||
await _context.InsertFakeUsersAsync(_categories, userCount); | ||
|
||
await _context.SaveChangesAsync(); | ||
|
||
_randomUser = (await _context.UserProfiles | ||
.OrderBy(x => x.Id) | ||
.Skip(Random.Shared.Next(userCount)) | ||
.Take(1) | ||
.FirstOrDefaultAsync())!; | ||
|
||
_service = scope.ServiceProvider.GetRequiredService<IUserSearchService>(); | ||
} | ||
|
||
[Benchmark] | ||
public async Task UserSearch_No_Filter() => | ||
await _service.GetUsersAsync(new UserSearchFilter()); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_FirstName() => | ||
await _service.GetUsersAsync(new UserSearchFilter { Name = _randomUser.FirstName }); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_LastName() => | ||
await _service.GetUsersAsync(new UserSearchFilter { Name = _randomUser.LastName }); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_UserName() => | ||
await _service.GetUsersAsync(new UserSearchFilter { Name = _randomUser.UserName }); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_Age_Of_Children() | ||
{ | ||
var minimumAge = Random.Shared.Next(0, 14); | ||
var maximumAge = Random.Shared.Next(minimumAge, 14); | ||
await _service.GetUsersAsync(new UserSearchFilter { MinimumChildAge = minimumAge, MaximumChildAge = maximumAge }); | ||
} | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_Category() => | ||
await _service.GetUsersAsync(new UserSearchFilter | ||
{ | ||
Categories = _categories | ||
.Select(category => category.Name) | ||
.Skip(Random.Shared.Next(0, _categories.Count)) | ||
.ToArray() | ||
}); | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_Gender_Of_Children() | ||
{ | ||
var genders = Enum.GetValues<Gender>(); | ||
await _service.GetUsersAsync(new UserSearchFilter { ChildGender = genders[Random.Shared.Next(0, genders.Length)] }); | ||
} | ||
|
||
[Benchmark] | ||
public async Task UserSearch_Filter_By_Address_Within_20_Kilometers() => | ||
await _service.GetUsersAsync(new UserSearchFilter | ||
{ | ||
Location = $"{_randomUser.Address}, {_randomUser.ZipCode} {_randomUser.City}", | ||
WithinRadiusKilometers = 20 | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.