mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
cleanup some non-urgent TODOs
This commit is contained in:
parent
bca4baffd4
commit
65602f6660
2 changed files with 23 additions and 15 deletions
|
|
@ -2,6 +2,9 @@
|
|||
xmlns:s="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
|
||||
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=6B3E6765_002D5B8B_002D4A23_002DAD12_002D7E2BC5F4D2E6_002Fd_003Awwwroot/@EntryIndexedValue"></s:String>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=6B3E6765_002D5B8B_002D4A23_002DAD12_002D7E2BC5F4D2E6_002Fd_003Awwwroot/@EntryIndexRemoved">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=6B3E6765_002D5B8B_002D4A23_002DAD12_002D7E2BC5F4D2E6_002Fd_003Awwwroot_002Fd_003Adist/@EntryIndexedValue">6B3E6765-5B8B-4A23-AD12-7E2BC5F4D2E6/d:wwwroot/d:dist</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/GeneratedCode/GeneratedFileMasks/=_002A_002EDesigner_002Ecs/@EntryIndexedValue"></s:String>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/GeneratedCode/GeneratedFileMasks/=_002A_002EDesigner_002Ecs/@EntryIndexRemoved">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue">True</s:Boolean>
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ namespace FilterLists.Data.Seed.Extensions
|
|||
{
|
||||
public static class SeedFilterListsDbContext
|
||||
{
|
||||
//TODO: consider handling deleted entities on seed
|
||||
//TODO: read entities from model and iterate over
|
||||
public static void SeedOrUpdate(this FilterListsDbContext dbContext, string dataPath)
|
||||
{
|
||||
dbContext.InsertOnDuplicateKeyUpdate<Language>(dataPath);
|
||||
|
|
@ -29,7 +27,6 @@ public static void SeedOrUpdate(this FilterListsDbContext dbContext, string data
|
|||
dbContext.InsertOnDuplicateKeyUpdate<SoftwareSyntax>(dataPath);
|
||||
}
|
||||
|
||||
//TODO: improve raw SQL against injection attacks
|
||||
private static void InsertOnDuplicateKeyUpdate<TEntityType>(this DbContext dbContext, string dataPath)
|
||||
where TEntityType : class
|
||||
{
|
||||
|
|
@ -47,16 +44,26 @@ private static void InsertOnDuplicateKeyUpdate<TEntityType>(this DbContext dbCon
|
|||
|
||||
private static List<IProperty> GetPropertiesLessValueGeneratedTimestamps(IEntityType entityType)
|
||||
{
|
||||
//TODO: filter dynamically from JSON
|
||||
return entityType.GetProperties().Where(x =>
|
||||
!new List<string> {"CreatedDateUtc", "ModifiedDateUtc", "ScrapedDateUtc", "UpdatedDateUtc"}
|
||||
.Contains(x.Name)).ToList();
|
||||
//TODO: get seed properties dynamically from JSON
|
||||
return entityType.GetProperties()
|
||||
.Where(x =>
|
||||
!new List<string>
|
||||
{
|
||||
"CreatedDateUtc",
|
||||
"ModifiedDateUtc",
|
||||
"ScrapedDateUtc",
|
||||
"UpdatedDateUtc"
|
||||
}
|
||||
.Contains(x.Name))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static string CreateValues<TEntityType>(IReadOnlyCollection<IProperty> properties, string dataPath)
|
||||
{
|
||||
return GetSeedRows<TEntityType>(dataPath).Select(row => CreateRowValues(properties, row)).Aggregate("",
|
||||
(current, rowValues) => current == "" ? rowValues : current + ", " + rowValues);
|
||||
return GetSeedRows<TEntityType>(dataPath)
|
||||
.Select(row => CreateRowValues(properties, row))
|
||||
.Aggregate("",
|
||||
(current, rowValues) => current == "" ? rowValues : current + ", " + rowValues);
|
||||
}
|
||||
|
||||
private static List<TEntityType> GetSeedRows<TEntityType>(string dataPath)
|
||||
|
|
@ -81,7 +88,6 @@ select FormatDataForMySql(property, value)).Aggregate("",
|
|||
(rowValues, value) => rowValues == "" ? "(" + value : rowValues + ", " + value) + ")";
|
||||
}
|
||||
|
||||
//TODO: use .NET, EF, or other library rather than maintaining this
|
||||
private static object FormatDataForMySql(IProperty property, object value)
|
||||
{
|
||||
if (value == null) return "NULL";
|
||||
|
|
@ -97,15 +103,14 @@ private static object FormatDataForMySql(IProperty property, object value)
|
|||
private static string CreateUpdates(IReadOnlyCollection<IProperty> properties)
|
||||
{
|
||||
var update =
|
||||
(from property in properties
|
||||
where !property.IsPrimaryKey()
|
||||
select property.Name + " = VALUES(" + property.Name + ")").Aggregate("",
|
||||
(updates, columnUpdates) => updates == "" ? columnUpdates : updates + ", " + columnUpdates);
|
||||
(from property in properties
|
||||
where !property.IsPrimaryKey()
|
||||
select property.Name + " = VALUES(" + property.Name + ")").Aggregate("",
|
||||
(updates, columnUpdates) => updates == "" ? columnUpdates : updates + ", " + columnUpdates);
|
||||
if (update == "") update = GetUpdateUnchangedColumnHack(properties);
|
||||
return update;
|
||||
}
|
||||
|
||||
//TODO: eliminate wasted IO updating unchanged column (https://stackoverflow.com/a/4596409/2343739)
|
||||
private static string GetUpdateUnchangedColumnHack(IEnumerable<IProperty> properties)
|
||||
{
|
||||
var firstId = properties.First(x => x.IsPrimaryKey()).Name;
|
||||
|
|
|
|||
Loading…
Reference in a new issue