File tree 8 files changed +15
-28
lines changed
8 files changed +15
-28
lines changed Original file line number Diff line number Diff line change @@ -69,12 +69,10 @@ protected override void OnModelCreating(ModelBuilder b)
69
69
b . Entity < User > ( ) . ToTable ( "tbmc_user" ) ;
70
70
b . Entity < ThreadPost > ( ) . ToTable ( $ "tbmc_f{ Fid } _thread") ;
71
71
b . Entity < ThreadMissingFirstReply > ( ) . ToTable ( "tbmc_thread_missingFirstReply" ) ;
72
- b . Entity < ReplyPost > ( ) . ToTable ( $ "tbmc_f{ Fid } _reply")
73
- . HasOne ( e => e . Content ) . WithOne ( ) . HasForeignKey < ReplyContent > ( e => e . Pid ) ;
72
+ b . Entity < ReplyPost > ( ) . ToTable ( $ "tbmc_f{ Fid } _reply") ;
74
73
b . Entity < ReplyContent > ( ) . ToTable ( $ "tbmc_f{ Fid } _reply_content") ;
75
74
b . Entity < ReplySignature > ( ) . ToTable ( "tbmc_reply_signature" ) . HasKey ( e => new { e . SignatureId , e . XxHash3 } ) ;
76
- b . Entity < SubReplyPost > ( ) . ToTable ( $ "tbmc_f{ Fid } _subReply")
77
- . HasOne ( e => e . Content ) . WithOne ( ) . HasForeignKey < SubReplyContent > ( e => e . Spid ) ;
75
+ b . Entity < SubReplyPost > ( ) . ToTable ( $ "tbmc_f{ Fid } _subReply") ;
78
76
b . Entity < SubReplyContent > ( ) . ToTable ( $ "tbmc_f{ Fid } _subReply_content") ;
79
77
80
78
_ = new RevisionWithSplitting < BaseThreadRevision >
Original file line number Diff line number Diff line change 1
1
// ReSharper disable PropertyCanBeMadeInitOnly.Global
2
2
namespace tbm . Crawler . Db . Post ;
3
3
4
- public abstract class PostWithContentAndAuthorExpGrade < TPostContent > : PostWithAuthorExpGrade
5
- where TPostContent : BasePostContent
4
+ public abstract class PostWithContentAndAuthorExpGrade : PostWithAuthorExpGrade
6
5
{
7
- public required TPostContent Content { get ; set ; }
6
+ [ NotMapped ] public byte [ ] ? Content { get ; set ; }
8
7
9
8
[ JsonConverter ( typeof ( ProtoBufRepeatedFieldJsonConverter < Content > ) ) ]
10
9
[ NotMapped ]
Original file line number Diff line number Diff line change 1
1
// ReSharper disable PropertyCanBeMadeInitOnly.Global
2
2
namespace tbm . Crawler . Db . Post ;
3
3
4
- public class ReplyPost : PostWithContentAndAuthorExpGrade < ReplyContent >
4
+ public class ReplyPost : PostWithContentAndAuthorExpGrade
5
5
{
6
6
[ Key ] [ Column ( TypeName = "bigint" ) ]
7
7
public ulong Pid { get ; set ; }
Original file line number Diff line number Diff line change 1
1
// ReSharper disable PropertyCanBeMadeInitOnly.Global
2
2
namespace tbm . Crawler . Db . Post ;
3
3
4
- public class SubReplyPost : PostWithContentAndAuthorExpGrade < SubReplyContent >
4
+ public class SubReplyPost : PostWithContentAndAuthorExpGrade
5
5
{
6
6
[ Column ( TypeName = "bigint" ) ]
7
7
public ulong Pid { get ; set ; }
Original file line number Diff line number Diff line change @@ -14,21 +14,13 @@ protected override IEnumerable<ReplyPost> ParseInternal
14
14
15
15
protected override ReplyPost Convert ( Reply inPost )
16
16
{
17
- var o = new ReplyPost
18
- {
19
- Content = null ! , // will get mutated by SimplifyImagesInReplyContent()
20
- ContentsProtoBuf = inPost . Content
21
- } ;
17
+ var o = new ReplyPost { ContentsProtoBuf = inPost . Content } ;
22
18
try
23
19
{
24
20
o . Pid = inPost . Pid ;
25
21
o . Floor = inPost . Floor ;
26
22
SimplifyImagesInReplyContent ( logger , ref inPost ) ;
27
- o . Content = new ( )
28
- {
29
- Pid = inPost . Pid ,
30
- ProtoBufBytes = Helper . SerializedProtoBufWrapperOrNullIfEmpty ( inPost . Content , Helper . WrapPostContent )
31
- } ;
23
+ o . Content = Helper . SerializedProtoBufWrapperOrNullIfEmpty ( inPost . Content , Helper . WrapPostContent ) ;
32
24
33
25
// AuthorId rarely respond with 0, Author should always be null with no guarantee
34
26
o . AuthorUid = inPost . AuthorId . NullIfZero ( ) ?? inPost . Author ? . Uid ?? 0 ;
Original file line number Diff line number Diff line change @@ -13,19 +13,12 @@ protected override IEnumerable<SubReplyPost> ParseInternal
13
13
14
14
protected override SubReplyPost Convert ( SubReply inPost )
15
15
{
16
- var o = new SubReplyPost
17
- {
18
- Content = new ( )
19
- {
20
- Spid = inPost . Spid ,
21
- ProtoBufBytes = Helper . SerializedProtoBufWrapperOrNullIfEmpty ( inPost . Content , Helper . WrapPostContent )
22
- } ,
23
- ContentsProtoBuf = inPost . Content
24
- } ;
16
+ var o = new SubReplyPost { ContentsProtoBuf = inPost . Content } ;
25
17
try
26
18
{
27
19
var author = inPost . Author ;
28
20
o . Spid = inPost . Spid ;
21
+ o . Content = Helper . SerializedProtoBufWrapperOrNullIfEmpty ( inPost . Content , Helper . WrapPostContent ) ;
29
22
o . AuthorUid = author . Uid ;
30
23
o . AuthorExpGrade = ( byte ) author . LevelId ;
31
24
o . PostedAt = inPost . Time ;
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ public override SaverChangeSet<ReplyPost> Save(CrawlerDbContext db)
17
17
r => new ReplyRevision { TakenAt = r . UpdatedAt ?? r . CreatedAt , Pid = r . Pid } ,
18
18
LinqKit . PredicateBuilder . New < ReplyPost > ( r => Posts . Keys . Contains ( r . Pid ) ) ) ;
19
19
20
+ db . ReplyContents . AddRange ( changeSet . NewlyAdded
21
+ . Select ( r => new ReplyContent { Pid = r . Pid , ProtoBufBytes = r . Content } ) ) ;
20
22
PostSaveHandlers += replyContentImageSaver . Save ( db , changeSet . NewlyAdded ) . Invoke ;
21
23
PostSaveHandlers += AuthorRevisionSaver . SaveAuthorExpGradeRevisions ( db , changeSet . AllAfter ) . Invoke ;
22
24
PostSaveHandlers += replySignatureSaver . Save ( db , changeSet . AllAfter ) . Invoke ;
Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ public override SaverChangeSet<SubReplyPost> Save(CrawlerDbContext db)
14
14
var changeSet = Save ( db , sr => sr . Spid ,
15
15
sr => new SubReplyRevision { TakenAt = sr . UpdatedAt ?? sr . CreatedAt , Spid = sr . Spid } ,
16
16
LinqKit . PredicateBuilder . New < SubReplyPost > ( sr => Posts . Keys . Contains ( sr . Spid ) ) ) ;
17
+
18
+ db . SubReplyContents . AddRange ( changeSet . NewlyAdded . Select ( sr =>
19
+ new SubReplyContent { Spid = sr . Spid , ProtoBufBytes = sr . Content } ) ) ;
17
20
PostSaveHandlers += AuthorRevisionSaver . SaveAuthorExpGradeRevisions ( db , changeSet . AllAfter ) . Invoke ;
18
21
19
22
return changeSet ;
You can’t perform that action at this time.
0 commit comments