-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
…already get locked @ `UserSaver.Save()` + record `MaybeExistingAndNewEntity` & method `SaveNewEntities()` to reuse parts in `(User|Post)Saver.Save()` * rename record `ExistingAndNewEntities` to `ExistingAndNewEntity` and remove suffix `-Entity` from its props @ SaverWithRevision.cs @ c#/crawler
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,12 +67,24 @@ private static bool IsTimestampingFieldName(string name) => name is nameof(BaseP | |
|
||
protected abstract NullFieldsBitMask GetRevisionNullFieldBitMask(string fieldName); | ||
Check failure on line 68 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (macos-latest) / build (crawler)
Check failure on line 68 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (macos-latest) / build (crawler)
Check failure on line 68 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (ubuntu-latest) / build (crawler)
Check failure on line 68 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (ubuntu-latest) / build (crawler)
Check failure on line 68 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (windows-latest) / build (crawler)
Check failure on line 68 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (windows-latest) / build (crawler)
|
||
|
||
protected record ExistingAndNewEntities<TEntity> | ||
(TEntity ExistingEntity, TEntity NewEntity) where TEntity : RowVersionedEntity; | ||
protected record ExistingAndNewEntity<TEntity>(TEntity Existing, TEntity New) where TEntity : RowVersionedEntity; | ||
protected record MaybeExistingAndNewEntity<TEntity>(TEntity? Existing, TEntity New) where TEntity : RowVersionedEntity; | ||
|
||
protected IEnumerable<ExistingAndNewEntity<TEntity>> SaveNewEntities<TEntity>( | ||
Check failure on line 73 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (macos-latest) / build (crawler)
Check failure on line 73 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (macos-latest) / build (crawler)
Check failure on line 73 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (ubuntu-latest) / build (crawler)
Check failure on line 73 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (ubuntu-latest) / build (crawler)
Check failure on line 73 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (windows-latest) / build (crawler)
Check failure on line 73 in c#/crawler/src/Tieba/Crawl/Saver/SaverWithRevision.cs GitHub Actions / runs-on (windows-latest) / build (crawler)
|
||
CrawlerDbContext db, | ||
IReadOnlyCollection<MaybeExistingAndNewEntity<TEntity>> maybeEntities) | ||
where TEntity : RowVersionedEntity | ||
{ | ||
db.Set<TEntity>().AddRange(maybeEntities | ||
.Where(entity => entity.Existing == null).Select(entity => entity.New)); | ||
return maybeEntities | ||
.Where(entity => entity.Existing != null) | ||
.Select(entity => new ExistingAndNewEntity<TEntity>(entity.Existing!, entity.New)); | ||
} | ||
|
||
protected void SaveExistingEntities<TEntity>( | ||
CrawlerDbContext db, | ||
IEnumerable<ExistingAndNewEntities<TEntity>> existingAndNewEntities) | ||
IEnumerable<ExistingAndNewEntity<TEntity>> existingAndNewEntities) | ||
where TEntity : RowVersionedEntity => | ||
existingAndNewEntities.ForEach(existingAndNew => | ||
{ | ||
|
@@ -100,7 +112,7 @@ on newNavigation.Metadata.Name equals existingNavigation.Metadata.Name | |
protected void SaveExistingEntityRevisions<TEntity, TRevision>( | ||
CrawlerDbContext db, | ||
Func<TEntity, TRevision> revisionFactory, | ||
IEnumerable<ExistingAndNewEntities<TEntity>> existingAndNewEntities, | ||
IEnumerable<ExistingAndNewEntity<TEntity>> existingAndNewEntities, | ||
UserSaver.FieldChangeIgnorance? userFieldUpdateIgnorance = null, | ||
UserSaver.FieldChangeIgnorance? userFieldRevisionIgnorance = null) | ||
where TEntity : RowVersionedEntity | ||
|