Skip to content

Commit db80307

Browse files
Fix tracking settings
1 parent f372d7a commit db80307

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

frameworks/CSharp/genhttp/Benchmarks/Model/Database.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public static class Database
88

99
static Database()
1010
{
11-
NoTrackingPool = new DatabaseContextPool<DatabaseContext>(factory: DatabaseContext.Create, maxSize: 512);
12-
TrackingPool = new DatabaseContextPool<DatabaseContext>(factory: DatabaseContext.Create, maxSize: 512);
11+
NoTrackingPool = new DatabaseContextPool<DatabaseContext>(factory: DatabaseContext.CreateNoTracking, maxSize: 512);
12+
TrackingPool = new DatabaseContextPool<DatabaseContext>(factory: DatabaseContext.CreateTracking, maxSize: 512);
1313
}
1414

1515
}

frameworks/CSharp/genhttp/Benchmarks/Model/DatabaseContext.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ namespace Benchmarks.Model;
55

66
public sealed class DatabaseContext : DbContext
77
{
8-
private static readonly Lazy<DbContextOptions<DatabaseContext>> Options = new(CreateOptions, LazyThreadSafetyMode.ExecutionAndPublication);
8+
private static readonly Lazy<DbContextOptions<DatabaseContext>> TrackingOptions = new(() => CreateOptions(true), LazyThreadSafetyMode.ExecutionAndPublication);
99

10-
public static DatabaseContext Create() => new(Options.Value);
10+
private static readonly Lazy<DbContextOptions<DatabaseContext>> NoTrackingOptions = new(() => CreateOptions(false), LazyThreadSafetyMode.ExecutionAndPublication);
1111

12-
private static DbContextOptions<DatabaseContext> CreateOptions()
12+
public static DatabaseContext CreateTracking() => new(TrackingOptions.Value, true);
13+
14+
public static DatabaseContext CreateNoTracking() => new(NoTrackingOptions.Value, false);
15+
16+
private static DbContextOptions<DatabaseContext> CreateOptions(bool tracking)
1317
{
1418
var services = new ServiceCollection();
1519

@@ -21,16 +25,20 @@ private static DbContextOptions<DatabaseContext> CreateOptions()
2125

2226
builder.UseInternalServiceProvider(provider)
2327
.UseNpgsql("Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;SSL Mode=Disable;Maximum Pool Size=512;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true")
24-
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
2528
.EnableThreadSafetyChecks(false)
2629
.UseModel(DatabaseContextModel.Instance);
2730

31+
if (!tracking)
32+
{
33+
builder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
34+
}
35+
2836
return builder.Options;
2937
}
3038

31-
internal DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
39+
internal DatabaseContext(DbContextOptions<DatabaseContext> options, bool tracking = false) : base(options)
3240
{
33-
ChangeTracker.AutoDetectChangesEnabled = false;
41+
ChangeTracker.AutoDetectChangesEnabled = tracking;
3442
}
3543

3644
public DbSet<World> World { get; set; }

0 commit comments

Comments
 (0)