Skip to content

Commit 56e93b4

Browse files
committed
* fix most of grammar errors in comments
* fix more violations of ReSharper inspections * add two common proper nouns in `UserDictionary` @ tbm.sln.DotSettings @ c#
1 parent 40bf7da commit 56e93b4

18 files changed

+37
-22
lines changed

c#/crawler/src/Tieba/Crawl/CrawlPost.cs

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ await Task.WhenAll(shouldCrawlParentPosts.Select(async t =>
128128
}
129129

130130
private Action<Exception> SaveThreadMissingFirstReply
131+
132+
// ReSharper disable once SuggestBaseTypeForParameter
131133
(Fid fid, Tid tid, SavedThreadsList savedThreads) => ex =>
132134
{
133135
if (ex is not EmptyPostListException) return;

c#/crawler/src/Tieba/Crawl/Crawler/ThreadArchiveCrawler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protected override IEnumerable<Request> GetRequestsForPage(Page page, Cancellati
1111
(req, common) => req.Data.Common = common,
1212
() => new ThreadResponse(), stoppingToken);
1313
return
14-
[ // passing CrawlRequestFlag.ThreadClientVersion602 in the second one in order to invokes ThreadParser.ShouldSkipParse()
14+
[ // passing CrawlRequestFlag.ThreadClientVersion602 in the second one in order to invoke ThreadParser.ShouldSkipParse()
1515
new(response),
1616
new(response, CrawlRequestFlag.ThreadClientVersion602)
1717
];

c#/crawler/src/Tieba/Crawl/Facade/BaseCrawlFacade.cs

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public async Task<BaseCrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf
8181
endPage = Math.Min(endPage, maxPage ?? Page.MaxValue);
8282
}, startPage, previousFailureCount: 0, stoppingToken);
8383

84+
// ReSharper disable once InvertIf
8485
if (!isStartPageCrawlFailed)
8586
{
8687
var pagesAfterStart = Enumerable.Range(

c#/crawler/src/Tieba/Crawl/Facade/ReplyCrawlFacade.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ from t in db.Threads.AsNoTracking().ForUpdate()
5050
where t.Tid == tid
5151
select t.Title).SingleOrDefault();
5252

53-
// thread title will be empty string as a fallback when the thread author haven't write title for this thread
53+
// thread title will be empty string as a fallback when the thread author haven't written title for this thread
5454
if (parentThreadTitle != "") return;
5555
var newTitle = replies.FirstOrDefault(r => r.Floor == 1)?.Title;
5656
if (newTitle == null) return;

c#/crawler/src/Tieba/Crawl/Facade/ThreadCrawlFacade.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected void ParseLatestRepliers(IEnumerable<Thread> threads) =>
4343
.OfType<TbClient.User>() // filter out nulls
4444

4545
// some rare deleted thread but still visible in 6.0.2 response
46-
// will have a latest replier uid=0 name="" nameShow=".*"
46+
// will have the latest replier uid=0 name="" nameShow=".*"
4747
.Where(u => u.Uid != 0)
4848
.Select(u => User.CreateLatestReplier(u.Uid, u.Name.NullIfEmpty(),
4949
u.Name == u.NameShow ? null : u.NameShow))

c#/crawler/src/Tieba/Crawl/Parser/BaseParser.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public void ParsePosts(
2323
.Where(u => u.CalculateSize() != 0)); // remove empty users
2424
}
2525

26-
protected abstract PostId PostIdSelector(TPost post);
26+
// ReSharper disable once UnusedMemberInSuper.Global
2727
protected abstract TPost Convert(TPostProtoBuf inPost);
2828
protected abstract IEnumerable<TPost> ParsePostsInternal(IList<TPostProtoBuf> inPosts, List<TbClient.User?> outUsers);
2929
protected virtual bool ShouldSkipParse(CrawlRequestFlag requestFlag) => false;
30+
protected abstract PostId PostIdSelector(TPost post);
3031
}

c#/crawler/src/Tieba/Crawl/Parser/ReplyParser.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ protected override ReplyPost Convert(Reply inPost)
4848
o.Content = Helper.SerializedProtoBufWrapperOrNullIfEmpty(inPost.Content,
4949
() => Helper.WrapPostContent(inPost.Content));
5050

51-
// AuthorId rarely respond with 0, Author should always be null but we can guarantee
51+
// AuthorId rarely respond with 0, Author should always be null with no guarantee
5252
o.AuthorUid = inPost.AuthorId.NullIfZero() ?? inPost.Author?.Uid ?? 0;
5353

54-
// value of AuthorExpGrade will be write back in ReplyCrawlFacade.FillAuthorInfoBackToReply()
54+
// value of AuthorExpGrade will be written back in ReplyCrawlFacade.FillAuthorInfoBackToReply()
5555
o.SubReplyCount = inPost.SubPostNumber.NullIfZero();
5656
o.PostedAt = inPost.Time;
5757
o.IsFold = (byte?)inPost.IsFold.NullIfZero();

c#/crawler/src/Tieba/Crawl/Parser/ThreadParser.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ protected override ThreadPost Convert(Thread inPost)
2323
#pragma warning restore S3358 // Ternary operators should not be nested
2424
o.IsGood = (byte?)inPost.IsGood.NullIfZero();
2525
o.TopicType = inPost.LivePostType.NullIfEmpty();
26-
o.Title = inPost.Title; // might be write back by ReplyCrawlFacade.SaveParentThreadTitle()
26+
o.Title = inPost.Title; // might be written back by ReplyCrawlFacade.SaveParentThreadTitle()
2727
o.AuthorUid = inPost.AuthorId;
2828
o.PostedAt = (uint)inPost.CreateTime;
2929
o.LatestReplyPostedAt = (uint)inPost.LastTimeInt;
3030
o.ReplyCount = inPost.ReplyNum < 0 ? 0 : (uint?)inPost.ReplyNum.NullIfZero(); // rarely respond with -1
3131
o.ViewCount = (uint?)inPost.ViewNum.NullIfZero();
3232
o.ShareCount = (uint?)inPost.ShareNum.NullIfZero();
3333

34-
// when the thread is livepost or Thread.AgreeNum == 0, the agree field will not exists
34+
// when the thread is livepost or Thread.AgreeNum == 0, the agree field will not exist
3535
o.AgreeCount = (int?)inPost.Agree?.AgreeNum.NullIfZero() ?? inPost.AgreeNum.NullIfZero();
3636
o.DisagreeCount = (int?)inPost.Agree?.DisagreeNum.NullIfZero();
3737
o.Geolocation = Helper.SerializedProtoBufOrNullIfEmpty(inPost.Location);

c#/crawler/src/Tieba/Crawl/Saver/CommonInSavers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private static bool IsLatestReplierUser(string pName, PropertyEntry p, EntityEnt
127127
// create another user instance with only fields of latest replier filled
128128
var latestReplier = User.CreateLatestReplier(user.Uid, user.Name, user.DisplayName);
129129

130-
// if they are same by fields values, the original one is a latest replier
130+
// if they are same by fields values, the original one is the latest replier
131131
// that previously generated by ParseLatestRepliers()
132132
return IsSameUser(user, latestReplier);
133133
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private Action SaveReplySignatures(CrawlerDbContext db, IEnumerable<ReplyPost> r
123123
{
124124
Helper.GetNowTimestamp(out var now);
125125
var signatures = replies
126-
.Where(r => r.SignatureId != null && r.Signature != null)
126+
.Where(r => r is {SignatureId: not null, Signature: not null})
127127
.DistinctBy(r => r.SignatureId)
128128
.Select(r => new ReplySignature
129129
{

c#/crawler/src/Tieba/Crawl/Saver/SaverChangeSet.cs

+2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ public SaverChangeSet(
2424

2525
public ReadOnlyCollection<(TPost Before, TPost After)> Existing { get; }
2626
public ReadOnlyCollection<TPost> NewlyAdded { get; }
27+
28+
// ReSharper disable once CollectionNeverUpdated.Global
2729
public ReadOnlyCollection<TPost> AllAfter { get; }
2830
}

c#/crawler/src/Tieba/Crawl/Saver/StaticCommonInSavers.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public abstract class StaticCommonInSavers
55
public delegate bool FieldChangeIgnoranceDelegate(
66
Type whichPostType, string propName, object? oldValue, object? newValue);
77

8-
// static field in this non generic class will be shared across all reified generic derived classes
8+
// static field in this non-generic class will be shared across all reified generic derived classes
99
protected static Dictionary<Type, Dictionary<string, PropertyInfo>> RevisionPropertiesCache { get; } = GetPropsKeyByType(
1010
[typeof(ThreadRevision), typeof(ReplyRevision), typeof(SubReplyRevision), typeof(UserRevision)]);
1111

@@ -37,22 +37,22 @@ when Math.Abs((newValue as int? ?? 0) - (oldValue as int? ?? 0)) <= 10:
3737
if (whichPostType == typeof(ThreadPost))
3838
{
3939
switch (propName)
40-
{ // will be update by ThreadLateCrawlerAndSaver
40+
{ // will be updated by ThreadLateCrawlerAndSaver
4141
case nameof(ThreadPost.AuthorPhoneType):
4242
// prevent overwrite existing value of field liker_id which is saved by legacy crawler
43-
// and Zan itself is deprecated by tieba so it shouldn't get updated
43+
// and Zan itself is deprecated by tieba, so it shouldn't get updated
4444
case nameof(ThreadPost.Zan):
4545
// possible randomly respond with null
4646
case nameof(ThreadPost.Geolocation) when newValue is null:
47-
// empty string means the author had not write a title
47+
// empty string means the author had not written a title
4848
// its value generated from the first reply within response of reply crawler
4949
// will be later set by ReplyCrawlFacade.SaveParentThreadTitle()
5050
case nameof(ThreadPost.Title)
5151
when newValue is ""
5252

5353
// prevent repeatedly update with different title
5454
// due to the thread is a multi forum topic thread
55-
// thus its title can be vary within the forum and within the thread
55+
// thus its title can be varied within the forum and within the thread
5656
|| (newValue is not "" && oldValue is not ""):
5757
// possible randomly respond with 0.NullIfZero()
5858
case nameof(ThreadPost.DisagreeCount) when newValue is null && oldValue is not null:
@@ -76,6 +76,8 @@ when newValue is ""
7676
{ // ignore revision that figures update existing old users that don't have ip geolocation
7777
if (whichPostType == typeof(User)
7878
&& propName == nameof(User.IpGeolocation) && oldValue is null) return true;
79+
80+
// ReSharper disable once InvertIf
7981
if (whichPostType == typeof(ThreadPost))
8082
{
8183
switch (propName)
@@ -89,7 +91,7 @@ when newValue is ""
8991
return false;
9092
});
9193

92-
private static Dictionary<Type, Dictionary<string, PropertyInfo>> GetPropsKeyByType(List<Type> types) =>
94+
private static Dictionary<Type, Dictionary<string, PropertyInfo>> GetPropsKeyByType(IEnumerable<Type> types) =>
9395
types.ToDictionary(type => type, type => type.GetProperties().ToDictionary(prop => prop.Name));
9496

9597
public record FieldChangeIgnoranceDelegates(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SubReplySaver(
2020
// FansNickname in sub reply response will always be null
2121
nameof(User.FansNickname) when oldValue is not null && newValue is null => true,
2222

23-
// DisplayName in users embedded in sub replies from response will be the legacy nick name
23+
// DisplayName in users embedded in sub replies from response will be the legacy nickname
2424
nameof(User.DisplayName) => true,
2525
_ => false
2626
}, (_, _, _, _) => false);

c#/crawler/src/Tieba/Crawl/ThreadLateCrawlerAndSaver.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private async Task<ThreadPost?> CrawlThread
9292
"Field phone_type is missing in response json.thread.thread_info, it might be a historical thread.")
9393

9494
// silent fail without any retry since the field `json.thread.thread_info`
95-
// might not exists in current and upcoming responses
95+
// might not exist in current and upcoming responses
9696
: null;
9797
#pragma warning restore S3358 // Ternary operators should not be nested
9898
}
@@ -119,6 +119,7 @@ private async Task<ThreadPost?> CrawlThread
119119
logger.LogError(e, "Exception");
120120
}
121121

122+
// ReSharper disable once InvertIf
122123
if (e is not TiebaException {ShouldRetry: false})
123124
{
124125
_locks.AcquireFailed(crawlerLockId, page: 1, failureCount);

c#/crawler/src/Tieba/Crawl/UserParserAndSaver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void ParseUsers(IEnumerable<TbClient.User> users) =>
4949
: (portrait, null);
5050

5151
var uid = el.Uid;
52-
if (uid == 0) return null; // in client version 12.x the last user in list will be a empty user with uid 0
52+
if (uid == 0) return null; // in client version 12.x the last user in list will be an empty user with uid 0
5353
var (portrait, portraitUpdatedAt) = ExtractPortrait(el.Portrait);
5454
if (uid < 0) // historical anonymous user
5555
{

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ public class ArchiveCrawlWorker(
1515
: ErrorableWorker(shouldExitOnException: true, shouldExitOnFinish: true)
1616
{
1717
// as of March 2019, tieba had restrict the max accepted value for page param of forum's threads api
18-
// any request with page offset that larger than 10k threads will be respond with results from the first page
18+
// any request with page offset that larger than 10k threads will be responded with results from the first page
1919
// in May 2023, they enlarged the limit to 100k threads: https://github.com/Starry-OvO/aiotieba/issues/124
2020
private const int MaxCrawlablePage = 3334; // 100k threads / 30 per request (from Rn param) = 3333.3...
21+
22+
// ReSharper disable once ConvertToConstant.Local
2123
private readonly string _forumName = "";
24+
25+
// ReSharper disable once ConvertToConstant.Local
2226
private readonly Fid _fid = 0;
2327

2428
// https://en.wikipedia.org/wiki/Moving_average#Cumulative_average

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private async Task RetryThreadLate(
6565
var fid = tidGroupByFid.Key;
6666
FailureCount FailureCountSelector(Tid tid) =>
6767

68-
// it should always contains only one page which is 1
68+
// it should always contain only one page which is 1
6969
failureCountWithPagesKeyByLockId[new(fid, tid)].Single().Value;
7070
var failureCountsKeyByTid = tidGroupByFid
7171
.Cast<Tid>().ToDictionary(tid => tid, FailureCountSelector);

c#/tbm.sln.DotSettings

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
33
<s:Boolean x:Key="/Default/UserDictionary/Words/=Roslynator/@EntryIndexedValue">True</s:Boolean>
44
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tieba/@EntryIndexedValue">True</s:Boolean>
55
<s:Boolean x:Key="/Default/UserDictionary/Words/=tesseract/@EntryIndexedValue">True</s:Boolean>
6+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Spid/@EntryIndexedValue">True</s:Boolean>
7+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Eithers/@EntryIndexedValue">True</s:Boolean>
68
<!-- table name prefixes -->
79
<s:Boolean x:Key="/Default/UserDictionary/Words/=tbm_/@EntryIndexedValue">True</s:Boolean>
810
<s:Boolean x:Key="/Default/UserDictionary/Words/=tbmi_/@EntryIndexedValue">True</s:Boolean>

0 commit comments

Comments
 (0)