-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* opt out entity splitting due to currently it only supporting `one-o…
…ne` relationships instead of desired `one-zeroOrOne`(optional entity), leading to inserting many records with all fields except the primary key with NULL values as placeholder record for `one-one` relation, so without re-introducing something like `IRevision.NullFieldsBitMask`, we can't distinguish between the original literal NULL value and these empty records: dotnet/efcore#27974 dotnet/efcore#29113 @ `TbmDbContext.OnModelCreating()` + abstract class `RevisionWithSplitting` as base class of all derived classes of `IRevision` * insert all entities returned from `RevisionWithSplitting.GetSplitEntities()` into DB @ `CommonInSavers.SavePostsOrUsers()` * change `abstract class BaseRevision` to `interface IRevision` to comply with single inheritance @ crawler
- Loading branch information
Showing
10 changed files
with
172 additions
and
60 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// ReSharper disable UnusedMember.Global | ||
namespace tbm.Crawler.Db.Revision | ||
{ | ||
public interface IRevision | ||
{ | ||
public uint TakenAt { get; set; } | ||
public ushort? NullFieldsBitMask { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,45 @@ | ||
// ReSharper disable PropertyCanBeMadeInitOnly.Global | ||
namespace tbm.Crawler.Db.Revision | ||
{ | ||
public class ReplyRevision : BaseRevision | ||
public class ReplyRevision : ReplyRevision.BaseReplyRevision | ||
{ | ||
public ulong Pid { get; set; } | ||
public uint Floor { get; set; } | ||
public uint SubReplyCount { get; set; } | ||
public abstract class BaseReplyRevision : RevisionWithSplitting<BaseReplyRevision> | ||
{ | ||
public ulong Pid { get; set; } | ||
} | ||
[NotMapped] public uint Floor | ||
{ | ||
get => GetSplitEntityValue<SplitFloor, uint>(r => r.Floor); | ||
set => SetSplitEntityValue<SplitFloor, uint>(value, (r, v) => r.Floor = v, | ||
() => new() {TakenAt = TakenAt, Pid = Pid, Floor = value}); | ||
} | ||
[NotMapped] public uint SubReplyCount | ||
{ | ||
get => GetSplitEntityValue<SplitSubReplyCount, uint>(r => r.SubReplyCount); | ||
set => SetSplitEntityValue<SplitSubReplyCount, uint>(value, (r, v) => r.SubReplyCount = v, | ||
() => new() {TakenAt = TakenAt, Pid = Pid, SubReplyCount = value}); | ||
} | ||
public ushort? IsFold { get; set; } | ||
public int AgreeCount { get; set; } | ||
[NotMapped] public int AgreeCount | ||
{ | ||
get => GetSplitEntityValue<SplitAgreeCount, int>(r => r.AgreeCount); | ||
set => SetSplitEntityValue<SplitAgreeCount, int>(value, (r, v) => r.AgreeCount = v, | ||
() => new() {TakenAt = TakenAt, Pid = Pid, AgreeCount = value}); | ||
} | ||
public int? DisagreeCount { get; set; } | ||
public byte[]? Geolocation { get; set; } | ||
|
||
public class SplitFloor : BaseReplyRevision | ||
{ | ||
public uint Floor { get; set; } | ||
} | ||
public class SplitSubReplyCount : BaseReplyRevision | ||
{ | ||
public uint SubReplyCount { get; set; } | ||
} | ||
public class SplitAgreeCount : BaseReplyRevision | ||
{ | ||
public int AgreeCount { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace tbm.Crawler.Db.Revision | ||
{ | ||
public abstract class RevisionWithSplitting<TSplitEntities> : IRevision | ||
{ | ||
public uint TakenAt { get; set; } | ||
public ushort? NullFieldsBitMask { get; set; } | ||
|
||
private Dictionary<Type, TSplitEntities> SplitEntities { get; } = new(); | ||
public IEnumerable<TSplitEntities> GetSplitEntities() => SplitEntities.Values; | ||
|
||
protected TValue? GetSplitEntityValue<TSplitEntity, TValue>(Func<TSplitEntity, TValue?> valueSelector) | ||
where TSplitEntity : class, TSplitEntities => | ||
SplitEntities.ContainsKey(typeof(TSplitEntity)) | ||
? valueSelector((TSplitEntity)SplitEntities[typeof(TSplitEntity)]!) | ||
: default; | ||
|
||
protected void SetSplitEntityValue<TSplitEntity, TValue>(TValue? value, | ||
Action<TSplitEntity, TValue?> valueSetter, Func<TSplitEntity> entityFactory) | ||
where TSplitEntity : class, TSplitEntities | ||
{ | ||
if (SplitEntities.ContainsKey(typeof(TSplitEntity))) | ||
valueSetter((TSplitEntity)SplitEntities[typeof(TSplitEntity)]!, value); | ||
else | ||
SplitEntities[typeof(TSplitEntity)] = entityFactory(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
// ReSharper disable PropertyCanBeMadeInitOnly.Global | ||
namespace tbm.Crawler.Db.Revision | ||
{ | ||
public class SubReplyRevision : BaseRevision | ||
public class SubReplyRevision : SubReplyRevision.BaseSubReplyRevision | ||
{ | ||
public ulong Spid { get; set; } | ||
public int AgreeCount { get; set; } | ||
public int DisagreeCount { get; set; } | ||
public abstract class BaseSubReplyRevision : RevisionWithSplitting<BaseSubReplyRevision> | ||
{ | ||
public ulong Spid { get; set; } | ||
} | ||
[NotMapped] public int AgreeCount | ||
{ | ||
get => GetSplitEntityValue<SplitAgreeCount, int>(r => r.AgreeCount); | ||
set => SetSplitEntityValue<SplitAgreeCount, int>(value, (r, v) => r.AgreeCount = v, | ||
() => new() {TakenAt = TakenAt, Spid = Spid, AgreeCount = value}); | ||
} | ||
[NotMapped] public int DisagreeCount | ||
{ | ||
get => GetSplitEntityValue<SplitDisagreeCount, int>(r => r.DisagreeCount); | ||
set => SetSplitEntityValue<SplitDisagreeCount, int>(value, (r, v) => r.DisagreeCount = v, | ||
() => new() {TakenAt = TakenAt, Spid = Spid, DisagreeCount = value}); | ||
} | ||
|
||
public class SplitAgreeCount : BaseSubReplyRevision | ||
{ | ||
public int AgreeCount { get; set; } | ||
} | ||
public class SplitDisagreeCount : BaseSubReplyRevision | ||
{ | ||
public int DisagreeCount { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
// ReSharper disable PropertyCanBeMadeInitOnly.Global | ||
namespace tbm.Crawler.Db.Revision | ||
{ | ||
public class ThreadRevision : BaseRevision | ||
public class ThreadRevision : ThreadRevision.BaseThreadRevision | ||
{ | ||
public ulong Tid { get; set; } | ||
public abstract class BaseThreadRevision : RevisionWithSplitting<BaseThreadRevision> | ||
{ | ||
public ulong Tid { get; set; } | ||
} | ||
public ulong? ThreadType { get; set; } | ||
public string? StickyType { get; set; } | ||
public string? TopicType { get; set; } | ||
public ushort? IsGood { get; set; } | ||
public uint? LatestReplyPostedAt { get; set; } | ||
public long? LatestReplierUid { get; set; } | ||
public uint? ReplyCount { get; set; } | ||
public uint ViewCount { get; set; } | ||
[NotMapped] public uint ViewCount | ||
{ | ||
get => GetSplitEntityValue<SplitViewCount, uint>(r => r.ViewCount); | ||
set => SetSplitEntityValue<SplitViewCount, uint>(value, (r, v) => r.ViewCount = v, | ||
() => new() {TakenAt = TakenAt, Tid = Tid, ViewCount = value}); | ||
} | ||
public uint? ShareCount { get; set; } | ||
public int? AgreeCount { get; set; } | ||
public int? DisagreeCount { get; set; } | ||
public byte[]? Geolocation { get; set; } | ||
|
||
public class SplitViewCount : BaseThreadRevision | ||
{ | ||
public uint ViewCount { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters