Skip to content

Commit 8d636a0

Browse files
committed
1 parent d482607 commit 8d636a0

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

c#/crawler/src/Db/CrawlerDbContext.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.EntityFrameworkCore.Infrastructure;
22
using Npgsql;
3+
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
34
using static tbm.Crawler.Db.Revision.Splitting.ReplyRevision;
45
using static tbm.Crawler.Db.Revision.Splitting.SubReplyRevision;
56
using static tbm.Crawler.Db.Revision.Splitting.ThreadRevision;
@@ -117,8 +118,8 @@ protected override void OnModelCreating(ModelBuilder b)
117118
b.Entity<Forum>().ToTable("tbm_forum");
118119
}
119120

120-
protected override void OnBuildingNpgsqlDataSource(NpgsqlDataSourceBuilder builder) =>
121-
builder.MapEnum<PostType>("tbmcr_triggeredBy", NpgsqlCamelCaseNameTranslator.Instance);
121+
protected override void OnConfiguringNpgsql(NpgsqlDbContextOptionsBuilder builder) =>
122+
builder.MapEnum<PostType>("tbmcr_triggeredBy", nameTranslator: NpgsqlCamelCaseNameTranslator.Instance);
122123

123124
public class ModelCacheKeyFactory : IModelCacheKeyFactory
124125
{ // https://stackoverflow.com/questions/51864015/entity-framework-map-model-class-to-table-at-run-time/51899590#51899590

c#/shared/src/Db/TbmDbContext.cs

+1-15
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ public class TbmDbContext<TModelCacheKeyFactory>(ILogger<TbmDbContext<TModelCach
135135
: TbmDbContext(logger)
136136
where TModelCacheKeyFactory : class, IModelCacheKeyFactory
137137
{
138-
[SuppressMessage("ReSharper", "StaticMemberInGenericType")]
139-
[SuppressMessage("Major Code Smell", "S2743:Static fields should not be used in generic types")]
140-
private static Lazy<NpgsqlDataSource>? _dataSourceSingleton;
141-
142138
// ReSharper disable once UnusedAutoPropertyAccessor.Global
143139
public required IConfiguration Config { private get; init; }
144140
public DbSet<ImageInReply> ImageInReplies => Set<ImageInReply>();
@@ -152,7 +148,7 @@ protected static void OnModelCreatingWithFid(ModelBuilder b, uint fid) =>
152148
[SuppressMessage("Style", "IDE0058:Expression value is never used")]
153149
protected override void OnConfiguring(DbContextOptionsBuilder options)
154150
{
155-
options.UseNpgsql(GetNpgsqlDataSource(Config.GetConnectionString("Main")).Value, OnConfiguringNpgsql)
151+
options.UseNpgsql(Config.GetConnectionString("Main"), OnConfiguringNpgsql)
156152
.ReplaceService<IModelCacheKeyFactory, TModelCacheKeyFactory>()
157153
.ReplaceService<IRelationalTransactionFactory, NoSavePointTransactionFactory>()
158154
.AddInterceptors(UseCurrentXactIdAsConcurrencyTokenCommandInterceptor.Instance)
@@ -180,14 +176,4 @@ protected override void OnModelCreating(ModelBuilder b)
180176
}
181177

182178
protected virtual void OnConfiguringNpgsql(NpgsqlDbContextOptionsBuilder builder) { }
183-
protected virtual void OnBuildingNpgsqlDataSource(NpgsqlDataSourceBuilder builder) { }
184-
185-
[SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields")]
186-
private Lazy<NpgsqlDataSource> GetNpgsqlDataSource(string? connectionString) =>
187-
_dataSourceSingleton ??= new(() =>
188-
{
189-
var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString);
190-
OnBuildingNpgsqlDataSource(dataSourceBuilder);
191-
return dataSourceBuilder.Build();
192-
});
193179
}

0 commit comments

Comments
 (0)