From a811dba06539e8ef555b93caffa0bde2718c90c4 Mon Sep 17 00:00:00 2001 From: n0099 Date: Tue, 11 Jun 2024 01:24:29 +0800 Subject: [PATCH] * fix all violations of Roslyn analyzer rules and ReSharper inspection * rename lambda param with type `ImageInReply` from `reply` to `image` @ `ReplyContentImageSaver.Save()` @ c# --- c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs | 3 +++ c#/crawler/src/Tieba/Crawl/Parser/Post/ReplyParser.cs | 4 +++- c#/crawler/src/Tieba/Crawl/Saver/ReplyContentImageSaver.cs | 4 ++-- c#/shared/src/Db/TbmDbContext.cs | 1 + c#/shared/src/TransformEntityWorker.cs | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs b/c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs index 769ff9fa..470c7463 100644 --- a/c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs +++ b/c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs @@ -1,7 +1,10 @@ // ReSharper disable PropertyCanBeMadeInitOnly.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global namespace tbm.Crawler.Db.Post; +#pragma warning disable AV1000 // Type name contains the word 'and', which suggests it has multiple purposes public abstract class PostWithContentAndAuthorExpGrade : PostWithAuthorExpGrade +#pragma warning restore AV1000 // Type name contains the word 'and', which suggests it has multiple purposes { [NotMapped] public byte[]? Content { get; set; } diff --git a/c#/crawler/src/Tieba/Crawl/Parser/Post/ReplyParser.cs b/c#/crawler/src/Tieba/Crawl/Parser/Post/ReplyParser.cs index 2069b686..b22d6c34 100644 --- a/c#/crawler/src/Tieba/Crawl/Parser/Post/ReplyParser.cs +++ b/c#/crawler/src/Tieba/Crawl/Parser/Post/ReplyParser.cs @@ -43,7 +43,9 @@ protected override ReplyPost Convert(Reply inPost) throw new InvalidDataException("Reply parse error.", e); } } - +} +public partial class ReplyParser +{ public static void SimplifyImagesInReplyContent (ILogger logger, ref Reply inPost) { diff --git a/c#/crawler/src/Tieba/Crawl/Saver/ReplyContentImageSaver.cs b/c#/crawler/src/Tieba/Crawl/Saver/ReplyContentImageSaver.cs index e04fb46e..92d1669f 100644 --- a/c#/crawler/src/Tieba/Crawl/Saver/ReplyContentImageSaver.cs +++ b/c#/crawler/src/Tieba/Crawl/Saver/ReplyContentImageSaver.cs @@ -36,7 +36,7 @@ where images.Keys.Contains(e.UrlFilename) .Where(pair => GlobalLockedImagesInReplyKeyByUrlFilename.TryAdd(pair.Key, pair.Value)) .ToDictionary(); newlyLockedImages.Values() - .Where(reply => !Monitor.TryEnter(reply, TimeSpan.FromSeconds(10))) + .Where(image => !Monitor.TryEnter(image, TimeSpan.FromSeconds(10))) .ForEach(image => logger.LogWarning( "Wait for locking newly locked image {} timed out after 10s", image.UrlFilename)); @@ -45,7 +45,7 @@ where images.Keys.Contains(e.UrlFilename) .Keys().Except(newlyLockedImages.Keys())) .ToDictionary(); alreadyLockedImages.Values() - .Where(reply => !Monitor.TryEnter(reply, TimeSpan.FromSeconds(10))) + .Where(image => !Monitor.TryEnter(image, TimeSpan.FromSeconds(10))) .ForEach(image => logger.LogWarning( "Wait for locking already locked image {} timed out after 10s", image.UrlFilename)); if (alreadyLockedImages.Count != 0) diff --git a/c#/shared/src/Db/TbmDbContext.cs b/c#/shared/src/Db/TbmDbContext.cs index 68355e07..01a5396d 100644 --- a/c#/shared/src/Db/TbmDbContext.cs +++ b/c#/shared/src/Db/TbmDbContext.cs @@ -130,6 +130,7 @@ private static void ManipulateCommand(DbCommand command) => "RETURNING pg_current_xact_id()::xid"); } } + public class TbmDbContext(ILogger> logger) : TbmDbContext(logger) where TModelCacheKeyFactory : class, IModelCacheKeyFactory diff --git a/c#/shared/src/TransformEntityWorker.cs b/c#/shared/src/TransformEntityWorker.cs index 757a7c6c..a88c9bc6 100644 --- a/c#/shared/src/TransformEntityWorker.cs +++ b/c#/shared/src/TransformEntityWorker.cs @@ -58,7 +58,7 @@ async Task SaveThenLog(int processedCount, Process currentProcess) logger.LogTrace("processedEntityCount:{} updatedEntityCount:{} elapsed:{}ms processMemory:{}MiB exceptions:{}", processedCount, updatedEntityCount, stopwatch.ElapsedMilliseconds, - currentProcess.PrivateMemorySize64 / 1024 / 1024, + currentProcess.PrivateMemorySize64 / 1024f / 1024, JsonSerializer.Serialize(exceptions, JsonSerializerOptions)); stopwatch.Restart(); }