minor cleanup

This commit is contained in:
Collin Barrett 2018-08-05 17:48:12 -05:00
parent 70aaad38e5
commit 0ed9bb650e
17 changed files with 114 additions and 91 deletions

View file

@ -24,10 +24,10 @@ public static void AddFilterListsApi(this IServiceCollection services)
private static void ConfigureCookiePolicy(this IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
services.Configure<CookiePolicyOptions>(opts =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
opts.CheckConsentNeeded = context => true;
opts.MinimumSameSitePolicy = SameSiteMode.None;
});
}
@ -38,14 +38,14 @@ private static void AddMvcCustom(this IServiceCollection services)
private static void AddRoutingCustom(this IServiceCollection services)
{
services.AddRouting(options => options.LowercaseUrls = true);
services.AddRouting(opts => opts.LowercaseUrls = true);
}
private static void AddSwaggerGenCustom(this IServiceCollection services)
{
services.AddSwaggerGen(c =>
services.AddSwaggerGen(opts =>
{
c.SwaggerDoc("v1",
opts.SwaggerDoc("v1",
new Info
{
Title = "FilterLists API",
@ -65,7 +65,7 @@ private static void AddSwaggerGenCustom(this IServiceCollection services)
Url = "https://github.com/collinbarrett/FilterLists/blob/master/LICENSE"
}
});
c.IncludeXmlComments(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath,
opts.IncludeXmlComments(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath,
"FilterLists.Api.xml"));
});
}

View file

@ -1,9 +1,11 @@
using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
[UsedImplicitly]
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
@ -12,10 +14,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
"languages",
table => new
{
Id = table.Column<int>("SMALLINT UNSIGNED", nullable: false)
Id = table.Column<int>("SMALLINT UNSIGNED")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
Iso6391 = table.Column<string>("VARCHAR(2)", nullable: true, defaultValueSql: "NULL"),
@ -24,7 +26,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
Iso6392T = table.Column<string>("VARCHAR(3)", nullable: true, defaultValueSql: "NULL"),
Iso6393 = table.Column<string>("VARCHAR(3)", nullable: true, defaultValueSql: "NULL"),
LocalName = table.Column<string>("VARCHAR(126)", nullable: true, defaultValueSql: "NULL"),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP"),
Name = table.Column<string>("VARCHAR(126)", nullable: true, defaultValueSql: "NULL")
},
constraints: table => { table.PrimaryKey("PK_languages", x => x.Id); });
@ -33,17 +35,17 @@ protected override void Up(MigrationBuilder migrationBuilder)
"licenses",
table => new
{
Id = table.Column<int>("TINYINT UNSIGNED", nullable: false)
Id = table.Column<int>("TINYINT UNSIGNED")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
DescriptionUrl = table.Column<string>("TEXT", nullable: true),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false),
Name = table.Column<string>("VARCHAR(126)", nullable: false),
PermissiveAdaptation = table.Column<bool>(nullable: false),
PermissiveCommercial = table.Column<bool>(nullable: false)
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP"),
Name = table.Column<string>("VARCHAR(126)"),
PermissiveAdaptation = table.Column<bool>(),
PermissiveCommercial = table.Column<bool>()
},
constraints: table => { table.PrimaryKey("PK_licenses", x => x.Id); });
@ -51,16 +53,16 @@ protected override void Up(MigrationBuilder migrationBuilder)
"maintainers",
table => new
{
Id = table.Column<int>("SMALLINT UNSIGNED", nullable: false)
Id = table.Column<int>("SMALLINT UNSIGNED")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
EmailAddress = table.Column<string>("VARCHAR(126)", nullable: true, defaultValueSql: "NULL"),
HomeUrl = table.Column<string>("TEXT", nullable: true),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false),
Name = table.Column<string>("VARCHAR(126)", nullable: false),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP"),
Name = table.Column<string>("VARCHAR(126)"),
TwitterHandle = table.Column<string>("VARCHAR(126)", nullable: true, defaultValueSql: "NULL")
},
constraints: table => { table.PrimaryKey("PK_maintainers", x => x.Id); });
@ -69,13 +71,13 @@ protected override void Up(MigrationBuilder migrationBuilder)
"rules",
table => new
{
Id = table.Column<int>("INT UNSIGNED", nullable: false)
Id = table.Column<int>("INT UNSIGNED")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
Raw = table.Column<string>("VARCHAR(8192)", nullable: false)
Raw = table.Column<string>("VARCHAR(8192)")
},
constraints: table => { table.PrimaryKey("PK_rules", x => x.Id); });
@ -83,16 +85,16 @@ protected override void Up(MigrationBuilder migrationBuilder)
"software",
table => new
{
Id = table.Column<int>("TINYINT UNSIGNED", nullable: false)
Id = table.Column<int>("TINYINT UNSIGNED")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
DownloadUrl = table.Column<string>("TEXT", nullable: true),
HomeUrl = table.Column<string>("TEXT", nullable: true),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false),
Name = table.Column<string>("VARCHAR(126)", nullable: false)
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP"),
Name = table.Column<string>("VARCHAR(126)")
},
constraints: table => { table.PrimaryKey("PK_software", x => x.Id); });
@ -100,15 +102,15 @@ protected override void Up(MigrationBuilder migrationBuilder)
"syntaxes",
table => new
{
Id = table.Column<int>("TINYINT UNSIGNED", nullable: false)
Id = table.Column<int>("TINYINT UNSIGNED")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
DefinitionUrl = table.Column<string>("TEXT", nullable: true),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false),
Name = table.Column<string>("VARCHAR(126)", nullable: false)
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP"),
Name = table.Column<string>("VARCHAR(126)")
},
constraints: table => { table.PrimaryKey("PK_syntaxes", x => x.Id); });
@ -116,10 +118,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
"filterlists",
table => new
{
Id = table.Column<int>("SMALLINT UNSIGNED", nullable: false)
Id = table.Column<int>("SMALLINT UNSIGNED")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
Description = table.Column<string>("TEXT", nullable: true),
@ -131,8 +133,8 @@ protected override void Up(MigrationBuilder migrationBuilder)
HomeUrl = table.Column<string>("TEXT", nullable: true),
IssuesUrl = table.Column<string>("TEXT", nullable: true),
LicenseId = table.Column<int>(nullable: true),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false),
Name = table.Column<string>("VARCHAR(126)", nullable: false),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP"),
Name = table.Column<string>("VARCHAR(126)"),
PolicyUrl = table.Column<string>("TEXT", nullable: true),
SubmissionUrl = table.Column<string>("TEXT", nullable: true),
SyntaxId = table.Column<int>(nullable: true),
@ -159,9 +161,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
"software_syntaxes",
table => new
{
SyntaxId = table.Column<int>(nullable: false),
SoftwareId = table.Column<int>(nullable: false),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
SyntaxId = table.Column<int>(),
SoftwareId = table.Column<int>(),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
},
@ -186,9 +188,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
"filterlists_languages",
table => new
{
FilterListId = table.Column<int>(nullable: false),
LanguageId = table.Column<int>(nullable: false),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
FilterListId = table.Column<int>(),
LanguageId = table.Column<int>(),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
},
@ -213,9 +215,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
"filterlists_maintainers",
table => new
{
FilterListId = table.Column<int>(nullable: false),
MaintainerId = table.Column<int>(nullable: false),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
FilterListId = table.Column<int>(),
MaintainerId = table.Column<int>(),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
},
@ -240,9 +242,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
"forks",
table => new
{
ForkFilterListId = table.Column<int>(nullable: false),
UpstreamFilterListId = table.Column<int>(nullable: false),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
ForkFilterListId = table.Column<int>(),
UpstreamFilterListId = table.Column<int>(),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
},
@ -267,9 +269,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
"merges",
table => new
{
MergeFilterListId = table.Column<int>(nullable: false),
UpstreamFilterListId = table.Column<int>(nullable: false),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
MergeFilterListId = table.Column<int>(),
UpstreamFilterListId = table.Column<int>(),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
},
@ -294,13 +296,13 @@ protected override void Up(MigrationBuilder migrationBuilder)
"snapshots",
table => new
{
Id = table.Column<int>("MEDIUMINT UNSIGNED", nullable: false)
Id = table.Column<int>("MEDIUMINT UNSIGNED")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
FilterListId = table.Column<int>(nullable: false),
FilterListId = table.Column<int>(),
HttpStatusCode = table.Column<string>("VARCHAR(3)", nullable: true, defaultValueSql: "NULL")
},
constraints: table =>
@ -318,12 +320,12 @@ protected override void Up(MigrationBuilder migrationBuilder)
"snapshots_rules",
table => new
{
AddedBySnapshotId = table.Column<int>(nullable: false),
RuleId = table.Column<int>(nullable: false),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
AddedBySnapshotId = table.Column<int>(),
RuleId = table.Column<int>(),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP")
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP"),
RemovedBySnapshotId = table.Column<int>(nullable: true)
},
constraints: table =>

View file

@ -1,7 +1,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
[UsedImplicitly]
public partial class AddIsCompletedFlagToSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)

View file

@ -1,8 +1,10 @@
using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
[UsedImplicitly]
public partial class AddSnapshotModifiedDateUtc : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)

View file

@ -1,7 +1,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
[UsedImplicitly]
public partial class AddDefaultLicenseId : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)

View file

@ -1,8 +1,10 @@
using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
[UsedImplicitly]
public partial class AddPublishedDate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)

View file

@ -1,8 +1,10 @@
using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
[UsedImplicitly]
public partial class DefaultOptionalDatesToNull : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)

View file

@ -1,7 +1,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
[UsedImplicitly]
public partial class addChatUrl : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)

View file

@ -2,12 +2,14 @@
using System;
using FilterLists.Data;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
namespace FilterLists.Api.Migrations
{
[UsedImplicitly]
[DbContext(typeof(FilterListsDbContext))]
internal class FilterListsDbContextModelSnapshot : ModelSnapshot
{

View file

@ -10,9 +10,10 @@ public static void Main(string[] args)
CreateWebHostBuilder(args).Build().Run();
}
private static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args)
.UseUrls("http://localhost:5000")
.UseApplicationInsights()
.UseStartup<Startup>();
private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://localhost:5000")
.UseApplicationInsights()
.UseStartup<Startup>();
}
}

View file

@ -24,12 +24,14 @@ public Startup(IConfiguration configuration)
private IConfiguration Configuration { get; }
[UsedImplicitly]
public void ConfigureServices(IServiceCollection services)
{
services.AddFilterListsServices(Configuration);
services.AddFilterListsApi();
}
[UsedImplicitly]
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
@ -50,33 +52,34 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc();
app.UseSwagger(c =>
app.UseSwagger(opts =>
{
c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = httpReq.Host.Value);
opts.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = httpReq.Host.Value);
//TODO: remove preprocessor directives
#if RELEASE
c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.BasePath = "/api");
opts.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.BasePath = "/api");
#endif
c.RouteTemplate = "docs/{documentName}/swagger.json";
UseLowercaseControllerNameInSwaggerHack(c);
opts.RouteTemplate = "docs/{documentName}/swagger.json";
UseLowercaseControllerNameInSwaggerHack(opts);
});
app.UseSwaggerUI(c =>
app.UseSwaggerUI(opts =>
{
c.SwaggerEndpoint("v1/swagger.json", "FilterLists API v1");
c.DocumentTitle = "FilterLists API v1";
c.RoutePrefix = "docs";
opts.SwaggerEndpoint("v1/swagger.json", "FilterLists API v1");
opts.DocumentTitle = "FilterLists API v1";
opts.RoutePrefix = "docs";
});
MigrateAndSeedDatabase(app);
}
//TODO: remove hack (https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/74#issuecomment-386762178)
private static void UseLowercaseControllerNameInSwaggerHack(SwaggerOptions c)
private static void UseLowercaseControllerNameInSwaggerHack(SwaggerOptions opts)
{
c.PreSerializeFilters.Add((document, request) =>
opts.PreSerializeFilters.Add((document, request) =>
{
var paths = document.Paths.ToDictionary(item => item.Key.ToLowerInvariant(), item => item.Value);
document.Paths.Clear();
foreach (var pathItem in paths) document.Paths.Add(pathItem.Key, pathItem.Value);
foreach (var pathItem in paths)
document.Paths.Add(pathItem.Key, pathItem.Value);
});
}
@ -85,8 +88,9 @@ private void MigrateAndSeedDatabase(IApplicationBuilder app)
var dataPath = Configuration.GetSection("DataDirectory").GetValue<string>("Path");
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetService<FilterListsDbContext>().Database.Migrate();
serviceScope.ServiceProvider.GetService<FilterListsDbContext>().SeedOrUpdate(dataPath);
var filterListsDbContext = serviceScope.ServiceProvider.GetService<FilterListsDbContext>();
filterListsDbContext.Database.Migrate();
filterListsDbContext.SeedOrUpdate(dataPath);
}
}
}

View file

@ -13,7 +13,8 @@ public ForksController(SeedService seedService) : base(seedService)
}
[HttpGet("seed")]
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<Fork, ForkSeedDto>(
typeof(Fork).GetProperty("UpstreamFilterListId"), typeof(Fork).GetProperty("ForkFilterListId")));
public async Task<IActionResult> Seed() =>
Json(await SeedService.GetAllAsync<Fork, ForkSeedDto>(typeof(Fork).GetProperty("UpstreamFilterListId"),
typeof(Fork).GetProperty("ForkFilterListId")));
}
}

View file

@ -22,7 +22,7 @@ public ListsController(SeedService seedService, FilterListService filterListServ
[HttpGet]
[Route("{id}")]
//TODO: respond with appropriate exception if negative id queried
public async Task<IActionResult> GetById(int id) => Json(await filterListService.GetDetailsAsync((uint)id));
public async Task<IActionResult> GetById(int id) => Json(await filterListService.GetDetailsAsync((uint) id));
[HttpGet("seed")]
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<FilterList, FilterListSeedDto>());

View file

@ -13,7 +13,8 @@ public MergesController(SeedService seedService) : base(seedService)
}
[HttpGet("seed")]
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<Merge, MergeSeedDto>(
typeof(Merge).GetProperty("MergeFilterListId"), typeof(Merge).GetProperty("UpstreamFilterListId")));
public async Task<IActionResult> Seed() =>
Json(await SeedService.GetAllAsync<Merge, MergeSeedDto>(typeof(Merge).GetProperty("MergeFilterListId"),
typeof(Merge).GetProperty("UpstreamFilterListId")));
}
}

View file

@ -12,14 +12,14 @@ namespace FilterLists.Services.DependencyInjection.Extensions
{
public static class ConfigureServicesCollection
{
public static void AddFilterListsServices(this IServiceCollection services, IConfiguration configuration)
public static void AddFilterListsServices(this IServiceCollection services, IConfiguration config)
{
services.AddSingleton(c => configuration);
services.AddSingleton(c => config);
services.AddEntityFrameworkMySql()
.AddDbContextPool<FilterListsDbContext>(options =>
options.UseMySql(configuration.GetConnectionString("FilterListsConnection"),
b => b.MigrationsAssembly("FilterLists.Api"))
.EnableSensitiveDataLogging());
.AddDbContextPool<FilterListsDbContext>(opts =>
opts.UseMySql(config.GetConnectionString("FilterListsConnection"),
x => x.MigrationsAssembly("FilterLists.Api"))
.EnableSensitiveDataLogging());
services.TryAddScoped<SnapshotService>();
services.TryAddScoped<FilterListService>();
services.TryAddScoped<RuleService>();

View file

@ -10,7 +10,7 @@ public static void AddRange<T>(this ICollection<T> destination, IEnumerable<T> s
destination.Add(item);
}
public static IEnumerable<IEnumerable<T>> Batch<T>(this IEnumerable<T> source, int batchSize)
public static IEnumerable<IEnumerable<T>> GetBatches<T>(this IEnumerable<T> source, int batchSize)
{
var batches = new List<T>(batchSize);
foreach (var item in source)

View file

@ -104,7 +104,7 @@ private static IEnumerable<string> GetRawRules(string content)
private IEnumerable<SnapshotBatchDe> GetSnapshotBatches(IEnumerable<string> rawRules)
{
return rawRules.Batch(BatchSize)
return rawRules.GetBatches(BatchSize)
.Select(rawRuleBatch => new SnapshotBatchDe(dbContext, snapshot, rawRuleBatch));
}