Skip to content

Commit

Permalink
* fix not invoking ThreadLatestReplierSaver.SaveFromThread() for ne…
Browse files Browse the repository at this point in the history
…w 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
  • Loading branch information
n0099 committed Jul 25, 2024
1 parent cc2eddc commit d0f9b09
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions c#/crawler/src/Tieba/Crawl/Saver/Post/PostSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected SaverChangeSet<TPost> Save<TRevision>(
Func<TPost, PostId> postIdSelector,
Func<TPost, TRevision> revisionFactory,
Func<IQueryable<TPost>, IQueryable<TPost>> postQueryTransformer,
Action<IEnumerable<ExistingAndNewEntity<TPost>>>? onBeforeSaveRevision = null)
Action<IEnumerable<MaybeExistingAndNewEntity<TPost>>>? onBeforeSaveRevision = null)
where TRevision : TBaseRevision
{
var existingPosts = postQueryTransformer(db.Set<TPost>().AsTracking()).ToList();
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions c#/crawler/src/Tieba/Crawl/Saver/Post/ThreadSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public override SaverChangeSet<ThreadPost> 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
{
Expand Down

0 comments on commit d0f9b09

Please sign in to comment.