From d0f9b09fd96c121384dca287bebe3883a998c29e Mon Sep 17 00:00:00 2001 From: n0099 Date: Thu, 25 Jul 2024 10:29:25 +0000 Subject: [PATCH] * fix not invoking `ThreadLatestReplierSaver.SaveFromThread()` for new threads leading to trying to save duplicate latest repliers as related entity of new thread @ `ThreadSaver.Save()` * now passing variable `maybeExistingAndNewPosts` instead of `existingAndNewPosts` as the param of callback `onBeforeSaveRevision()` @ `PostSaver.Save()` @ c#/crawler --- c#/crawler/src/Tieba/Crawl/Saver/Post/PostSaver.cs | 4 ++-- c#/crawler/src/Tieba/Crawl/Saver/Post/ThreadSaver.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/c#/crawler/src/Tieba/Crawl/Saver/Post/PostSaver.cs b/c#/crawler/src/Tieba/Crawl/Saver/Post/PostSaver.cs index 9c8aebed..d0405362 100644 --- a/c#/crawler/src/Tieba/Crawl/Saver/Post/PostSaver.cs +++ b/c#/crawler/src/Tieba/Crawl/Saver/Post/PostSaver.cs @@ -26,7 +26,7 @@ protected SaverChangeSet Save( Func postIdSelector, Func revisionFactory, Func, IQueryable> postQueryTransformer, - Action>>? onBeforeSaveRevision = null) + Action>>? onBeforeSaveRevision = null) where TRevision : TBaseRevision { var existingPosts = postQueryTransformer(db.Set().AsTracking()).ToList(); @@ -41,7 +41,7 @@ from existingPost in existingPostsWithSameId.DefaultIfEmpty() var existingAndNewPosts = SaveNewEntities(db, maybeExistingAndNewPosts).ToList(); SaveExistingEntities(db, existingAndNewPosts); - onBeforeSaveRevision?.Invoke(existingAndNewPosts); + onBeforeSaveRevision?.Invoke(maybeExistingAndNewPosts); SaveExistingEntityRevisions(db, revisionFactory, existingAndNewPosts); return new(postIdSelector, existingPostsBeforeMerge, Posts.Values, existingPosts); } diff --git a/c#/crawler/src/Tieba/Crawl/Saver/Post/ThreadSaver.cs b/c#/crawler/src/Tieba/Crawl/Saver/Post/ThreadSaver.cs index a5cab2a7..426f3d4a 100644 --- a/c#/crawler/src/Tieba/Crawl/Saver/Post/ThreadSaver.cs +++ b/c#/crawler/src/Tieba/Crawl/Saver/Post/ThreadSaver.cs @@ -16,9 +16,9 @@ public override SaverChangeSet Save(CrawlerDbContext db) => Save(db, posts => posts .Where(th => Posts.Keys.Contains(th.Tid)) .Include(th => th.LatestReplier), - existingAndNewPosts => + maybeEntities => PostSaveHandlers += threadLatestReplierSaver.SaveFromThread(db, - existingAndNewPosts.Select(t => t.Existing).ToList())); + maybeEntities.Select(entity => entity.Existing ?? entity.New).ToList())); } public partial class ThreadSaver {