Skip to content

Commit 77e25ff

Browse files
committed
- prop Fid @ Db.Post.PostContent.BasePostContent, all its derived classes & all its usages
- param `fid` @ `Tieba.Crawl.Saver.Related.ReplyContentImageSaver.Save()`, also affected its usage at `Worker.ProcessImagesInAllReplyContentsWorker.DoWork()` * replace where clause on the removed prop `(Sub)?ReplyContents.Fid` with correlated subquery from (sub) replies table @ `Worker.PushAllPostContentsIntoSonicWorker.DoWork()` + prop `SubReplies`, partial revert 40bf7da @ `Db.CrawlerDbContext` @ crawler - prop `Fid` @ `Db.ReplyContentImage` @ shared @ c#
1 parent 5bf8736 commit 77e25ff

9 files changed

Lines changed: 10 additions & 14 deletions

File tree

c#/crawler/src/Db/CrawlerDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class CrawlerDbContext(ILogger<CrawlerDbContext> logger)
2121
public DbSet<ReplyPost> Replies => Set<ReplyPost>();
2222
public DbSet<ReplySignature> ReplySignatures => Set<ReplySignature>();
2323
public DbSet<ReplyContent> ReplyContents => Set<ReplyContent>();
24+
public DbSet<SubReplyPost> SubReplies => Set<SubReplyPost>();
2425
public DbSet<SubReplyContent> SubReplyContents => Set<SubReplyContent>();
2526
public DbSet<Forum> Forums => Set<Forum>();
2627

c#/crawler/src/Db/Post/PostContent/BasePostContent.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ namespace tbm.Crawler.Db.Post.PostContent;
33

44
public abstract class BasePostContent : RowVersionedEntity
55
{
6-
public uint Fid { get; set; }
76
public byte[]? ProtoBufBytes { get; set; }
87
}

c#/crawler/src/Tieba/Crawl/Saver/Post/ReplySaver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public partial class ReplySaver(
1818
posts => posts.Where(r => Posts.Keys.Contains(r.Pid)));
1919

2020
db.ReplyContents.AddRange(changeSet.NewlyAdded // https://github.com/dotnet/efcore/issues/33945
21-
.Select(r => new ReplyContent {Fid = Fid, Pid = r.Pid, ProtoBufBytes = r.Content}));
22-
PostSaveHandlers += replyContentImageSaver.Save(db, Fid, changeSet.NewlyAdded);
21+
.Select(r => new ReplyContent {Pid = r.Pid, ProtoBufBytes = r.Content}));
22+
PostSaveHandlers += replyContentImageSaver.Save(db, changeSet.NewlyAdded);
2323
PostSaveHandlers += replySignatureSaver.Save(db, changeSet.AllParsed);
2424

2525
return changeSet;

c#/crawler/src/Tieba/Crawl/Saver/Post/SubReplySaver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class SubReplySaver(
1616
posts => posts.Where(sr => Posts.Keys.Contains(sr.Spid)));
1717

1818
db.SubReplyContents.AddRange(changeSet.NewlyAdded.Select(sr => // https://github.com/dotnet/efcore/issues/33945
19-
new SubReplyContent {Fid = Fid, Spid = sr.Spid, ProtoBufBytes = sr.Content}));
19+
new SubReplyContent {Spid = sr.Spid, ProtoBufBytes = sr.Content}));
2020

2121
return changeSet;
2222
}

c#/crawler/src/Tieba/Crawl/Saver/Related/ReplyContentImageSaver.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Dispose()
2727
}
2828
}
2929

30-
public Action Save(CrawlerDbContext db, Fid fid, IEnumerable<ReplyPost.Parsed> replies)
30+
public Action Save(CrawlerDbContext db, IEnumerable<ReplyPost.Parsed> replies)
3131
{
3232
var replyContentImages = (
3333
from r in replies
@@ -37,7 +37,6 @@ from c in r.ContentsProtoBuf
3737
ReplyParser.ValidateContentImageFilenameRegex().IsMatch(c.OriginSrc)
3838
select new ReplyContentImage
3939
{
40-
Fid = fid,
4140
Pid = r.Pid,
4241
ImageInReply = new()
4342
{
@@ -105,7 +104,6 @@ on existingOrNew.UrlFilename equals replyContentImage.ImageInReply.UrlFilename
105104
select (existingOrNew, replyContentImage))
106105
.ForEach(t => t.replyContentImage.ImageInReply = t.existingOrNew);
107106
var existingReplyContentImages = db.ReplyContentImages.AsNoTracking()
108-
.Where(e => e.Fid == fid)
109107
.FilterByItems(replyContentImages, (existing, newOrExisting) =>
110108
existing.Pid == newOrExisting.Pid
111109
&& existing.ImageInReply.UrlFilename == newOrExisting.ImageInReply.UrlFilename)

c#/crawler/src/Worker/ProcessImagesInAllReplyContentsWorker.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ await Transform(
2828
readingEntity => readingEntity.Pid,
2929
readingEntity => new()
3030
{
31-
Fid = fid,
3231
Pid = readingEntity.Pid,
3332
ProtoBufBytes = readingEntity.ProtoBufBytes,
3433
Version = readingEntity.Version
@@ -54,10 +53,9 @@ await Transform(
5453
var p = ee.Property(e => e.ProtoBufBytes);
5554
p.IsModified = !ByteArrayEqualityComparer.Instance.Equals(p.OriginalValue, p.CurrentValue);
5655
});
57-
_ = replyContentImageSaver.Save(writingDb, fid,
56+
_ = replyContentImageSaver.Save(writingDb,
5857
replyContentsKeyByPid.Select(pair => new ReplyPost.Parsed
5958
{
60-
Fid = fid,
6159
Pid = pair.Key,
6260
Content = null!,
6361
ContentsProtoBuf = pair.Value

c#/crawler/src/Worker/PushAllPostContentsIntoSonicWorker.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ protected override async Task DoWork(CancellationToken stoppingToken)
3636
var forumIndex = (index + 1) * 2; // counting from one, including both reply and sub reply
3737

3838
_ = await pusher.Ingest.FlushBucketAsync($"{pusher.CollectionPrefix}replies_content", $"f{fid}");
39-
var replyContents = from r in db.ReplyContents.AsNoTracking() where r.Fid == fid select r;
39+
var replyContents = from r in db.ReplyContents.AsNoTracking()
40+
where db.Replies.Where(e => e.Fid == fid).Select(e => e.Pid).Contains(r.Pid) select r;
4041
pushedPostCount += PushPostContentsWithTiming(fid, forumIndex - 1, forumCount, "replies",
4142
replyCount, totalPostCount, pushedPostCount, replyContents,
4243
r => pusher.PushPost(fid, "replies", r.Pid, Helper.ParseThenUnwrapPostContent(r.ProtoBufBytes)), stoppingToken);
4344
await TriggerConsolidate();
4445

4546
_ = await pusher.Ingest.FlushBucketAsync($"{pusher.CollectionPrefix}subReplies_content", $"f{fid}");
46-
var subReplyContents = from sr in db.SubReplyContents.AsNoTracking() where sr.Fid == fid select sr;
47+
var subReplyContents = from sr in db.SubReplyContents.AsNoTracking()
48+
where db.SubReplies.Where(e => e.Fid == fid).Select(e => e.Spid).Contains(sr.Spid) select sr;
4749
pushedPostCount += PushPostContentsWithTiming(fid, forumIndex, forumCount, "sub replies",
4850
subReplyCount, totalPostCount, pushedPostCount, subReplyContents,
4951
sr => pusher.PushPost(fid, "subReplies", sr.Spid, Helper.ParseThenUnwrapPostContent(sr.ProtoBufBytes)), stoppingToken);

c#/imagePipeline/src/ImageBatchConsumingWorker.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ IEnumerable<ImageKeyWithMatrix> GetImagesInCurrentFid()
218218
// try to know which fid owns current image batch
219219
return imageKeysWithMatrix.IntersectBy(
220220
from replyContentImage in db.ReplyContentImages.AsNoTracking()
221-
where replyContentImage.Fid == fid
222221
where imageKeysWithMatrix
223222
.Select(imageKeyWithMatrix => imageKeyWithMatrix.ImageId)
224223
.Contains(replyContentImage.ImageId)

c#/shared/src/Db/ReplyContentImage.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace tbm.Shared.Db;
55

66
public class ReplyContentImage : EntityWithImageId
77
{
8-
public uint Fid { get; set; }
98
[Column(TypeName = "bigint")]
109
public ulong Pid { get; set; }
1110
public required ImageInReply ImageInReply { get; set; }

0 commit comments

Comments
 (0)