Skip to content

Commit c2f3a7e

Browse files
committed
* fix all violation of Roslyn analyzer rules and ReSharper inspections
* rename variable `nonTracked` to `notTracked` in linq query syntax @ `SaverChangeSet.AllAfter` * fix outdated comments @ SaverWithRevision.cs @ crawler * rename params of `(Except|Intersect)ByKey()` from `first` & `second` to `pairs` & `keys` @ shared/ExtensionMethods.cs @ c#
1 parent 2ed6374 commit c2f3a7e

File tree

7 files changed

+24
-26
lines changed

7 files changed

+24
-26
lines changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using LinqKit;
2-
31
namespace tbm.Crawler.Tieba.Crawl.Saver.Post;
42

53
public abstract class PostSaver<TPost, TBaseRevision, TPostId>(

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

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using LinqKit;
2-
31
namespace tbm.Crawler.Tieba.Crawl.Saver.Post;
42

53
public partial class ThreadSaver(

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

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ private void Save<TPost, TRevision, TValue>(
9191

9292
// locking key only using AuthorRevision.Fid and Uid, ignoring TriggeredBy
9393
// this prevents inserting multiple entities with similar time and other fields with the same values
94+
// ReSharper disable once NotAccessedPositionalProperty.Global
95+
// ReSharper disable once NotAccessedPositionalProperty.Global
9496
public record UniqueAuthorRevision(Fid Fid, Uid Uid);
9597

9698
private sealed class LatestAuthorRevisionProjection<TValue>

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public class SaverChangeSet<TPost>(
2121

2222
// https://stackoverflow.com/questions/3404975/left-outer-join-in-linq/23558389#23558389
2323
public IReadOnlyCollection<TPost> AllAfter { get; } = (
24-
from nonTracked in existingAfterAndNewlyAdded
24+
from notTracked in existingAfterAndNewlyAdded
2525
join inTracking in existingAfterInTracking
26-
on postIdSelector(nonTracked) equals postIdSelector(inTracking) into inTrackings
26+
on postIdSelector(notTracked) equals postIdSelector(inTracking) into inTrackings
2727
from inTracking in inTrackings.DefaultIfEmpty()
28-
select inTracking ?? nonTracked).ToList().AsReadOnly();
28+
select inTracking ?? notTracked).ToList().AsReadOnly();
2929
}

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,8 @@ public partial class SaverWithRevision<TBaseRevision, TRevisionId>
6262
}
6363
public partial class SaverWithRevision<TBaseRevision, TRevisionId>
6464
{
65-
private static bool IsTimestampingFieldName(string name) => name is nameof(BasePost.LastSeenAt)
66-
or nameof(TimestampedEntity.CreatedAt) or nameof(TimestampedEntity.UpdatedAt);
67-
6865
protected abstract NullFieldsBitMask GetRevisionNullFieldBitMask(string fieldName);
6966

70-
protected record ExistingAndNewEntity<TEntity>(TEntity Existing, TEntity New) where TEntity : RowVersionedEntity;
71-
protected record MaybeExistingAndNewEntity<TEntity>(TEntity? Existing, TEntity New) where TEntity : RowVersionedEntity;
72-
7367
protected IEnumerable<ExistingAndNewEntity<TEntity>> SaveNewEntities<TEntity>(
7468
CrawlerDbContext db,
7569
IReadOnlyCollection<MaybeExistingAndNewEntity<TEntity>> maybeEntities)
@@ -103,7 +97,7 @@ on newNavigation.Metadata.Name equals existingNavigation.Metadata.Name
10397

10498
// rollback changes that overwrite original values with the default value 0 or null
10599
// for all fields of TimestampedEntity and BasePost.LastSeenAt
106-
// this will also affect the entity instance which entityInTracking references to it
100+
// this will also affect the entity instance which existingEntity references to it
107101
entityEntry.Properties
108102
.Where(prop => prop.IsModified && IsTimestampingFieldName(prop.Metadata.Name))
109103
.ForEach(prop => prop.IsModified = false);
@@ -141,7 +135,7 @@ protected void SaveExistingEntityRevisions<TEntity, TRevision>(
141135
pName, p.OriginalValue, p.CurrentValue)))
142136
{
143137
p.IsModified = false;
144-
continue; // skip following revision check
138+
continue; // skip any further revision check
145139
}
146140
if (FieldRevisionIgnorance(
147141
pName, p.OriginalValue, p.CurrentValue)
@@ -151,7 +145,7 @@ protected void SaveExistingEntityRevisions<TEntity, TRevision>(
151145

152146
if (!IRevisionProperties.Cache[typeof(TRevision)].TryGetValue(pName, out var revisionProp))
153147
{
154-
object? ToHexWhenByteArray(object? value) =>
148+
static object? ToHexWhenByteArray(object? value) =>
155149
value is byte[] bytes ? bytes.ToHex() : value;
156150
logger.LogWarning("Updating field {} is not existing in revision table, " +
157151
"newValue={}, oldValue={}, newObject={}, oldObject={}",
@@ -163,7 +157,7 @@ protected void SaveExistingEntityRevisions<TEntity, TRevision>(
163157
{
164158
revision ??= revisionFactory(existingEntity);
165159

166-
// quote from MSDN https://learn.microsoft.com/en-us/dotnet/api/system.reflection.propertyinfo.setvalue
160+
// https://learn.microsoft.com/en-us/dotnet/api/system.reflection.propertyinfo.setvalue
167161
// If the property type of this PropertyInfo object is a value type and value is null
168162
// the property will be set to the default value for that type.
169163
// https://stackoverflow.com/questions/3049477/propertyinfo-setvalue-and-nulls
@@ -195,4 +189,10 @@ protected void SaveExistingEntityRevisions<TEntity, TRevision>(
195189
.GroupBy(pair => pair.Key, pair => pair.Value)
196190
.ForEach(g => AddSplitRevisionsDelegatesKeyByEntityType.Value[g.Key](db, g));
197191
}
192+
193+
private static bool IsTimestampingFieldName(string name) => name is nameof(BasePost.LastSeenAt)
194+
or nameof(TimestampedEntity.CreatedAt) or nameof(TimestampedEntity.UpdatedAt);
195+
196+
protected record ExistingAndNewEntity<TEntity>(TEntity Existing, TEntity New) where TEntity : RowVersionedEntity;
197+
protected record MaybeExistingAndNewEntity<TEntity>(TEntity? Existing, TEntity New) where TEntity : RowVersionedEntity;
198198
}

c#/shared/src/ExtensionMethods.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public static IEnumerable<TValue> Values<TKey, TValue>(this IEnumerable<KeyValue
3939
pairs.Select(i => i.Value);
4040

4141
public static IEnumerable<KeyValuePair<TKey, TValue>> ExceptByKey<TKey, TValue>(
42-
this IEnumerable<KeyValuePair<TKey, TValue>> first,
43-
IEnumerable<TKey> second) =>
44-
first.ExceptBy(second, pair => pair.Key);
42+
this IEnumerable<KeyValuePair<TKey, TValue>> pairs,
43+
IEnumerable<TKey> keys) =>
44+
pairs.ExceptBy(keys, pair => pair.Key);
4545
public static IEnumerable<KeyValuePair<TKey, TValue>> IntersectByKey<TKey, TValue>(
46-
this IEnumerable<KeyValuePair<TKey, TValue>> first,
47-
IEnumerable<TKey> second) =>
48-
first.IntersectBy(second, pair => pair.Key);
46+
this IEnumerable<KeyValuePair<TKey, TValue>> pairs,
47+
IEnumerable<TKey> keys) =>
48+
pairs.IntersectBy(keys, pair => pair.Key);
4949

5050
public static IEnumerable<T> Flatten2<T>(this IEnumerable<IEnumerable<T>> source) =>
5151
source.SelectMany(i => i);

c#/shared/tbm.Shared.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
99
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
1010
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
11-
<PackageReference Include="SuperLinq" Version="6.1.0" />
11+
<PackageReference Include="SuperLinq" Version="6.2.0" />
1212
</ItemGroup>
1313
<Choose>
1414
<When Condition="'$(Configuration)' == 'Release'">
@@ -18,12 +18,12 @@
1818
<PackageReference ExcludeAssets="compile" Include="codecracker.CSharp" Version="1.1.0" />
1919
<PackageReference ExcludeAssets="compile" Include="CSharpGuidelinesAnalyzer" Version="3.8.5" />
2020
<PackageReference ExcludeAssets="compile" Include="IDisposableAnalyzers" Version="4.0.8" />
21-
<PackageReference ExcludeAssets="compile" Include="Meziantou.Analyzer" Version="2.0.160" />
21+
<PackageReference ExcludeAssets="compile" Include="Meziantou.Analyzer" Version="2.0.161" />
2222
<PackageReference ExcludeAssets="compile" Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
2323
<PackageReference ExcludeAssets="compile" Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48" />
2424
<PackageReference ExcludeAssets="compile" Include="Roslynator.Analyzers" Version="4.12.4" />
2525
<PackageReference ExcludeAssets="compile" Include="SharpSource" Version="1.24.0" />
26-
<PackageReference ExcludeAssets="compile" Include="SonarAnalyzer.CSharp" Version="9.28.0.94264" />
26+
<PackageReference ExcludeAssets="compile" Include="SonarAnalyzer.CSharp" Version="9.30.0.95878" />
2727
<PackageReference ExcludeAssets="compile" Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556" />
2828
</ItemGroup>
2929
</When>

0 commit comments

Comments
 (0)