NightOwl888 commented on code in PR #821: URL: https://github.com/apache/lucenenet/pull/821#discussion_r1165888618
########## src/Lucene.Net.Benchmark/ByTask/Tasks/ReadTask.cs: ########## @@ -48,8 +49,10 @@ public abstract class ReadTask : PerfTask { private readonly IQueryMaker queryMaker; + [SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "This is a SonarCloud issue")] + [SuppressMessage("CodeQuality", "S1699:Constructors should only call non-overridable methods", Justification = "Required for continuity with Lucene's design")] protected ReadTask(PerfRunData runData) // LUCENENET: CA1012: Abstract types should not have constructors (marked protected) - : base(runData) + : this(runData, null) Review Comment: Let's add a label here to improve readability `: this(runData, queryMaker: null)` ########## src/Lucene.Net.Benchmark/ByTask/PerfRunData.cs: ########## @@ -98,7 +99,15 @@ public class PerfRunData : IDisposable private readonly IDictionary<string, object> perfObjects = new Dictionary<string, object>(); // constructor - public PerfRunData(Config config) + public PerfRunData(Config config) : this(config, true) + { + } + + // LUCENENET specific - added performReinit parameter to allow subclasses to skip reinit + // since it's a virtual method. Subclass can call that method itself if needed. + [SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "This is a SonarCloud issue")] + [SuppressMessage("CodeQuality", "S1699:Constructors should only call non-overridable methods", Justification = "Required for continuity with Lucene's design")] + protected PerfRunData(Config config, bool performReinit) Review Comment: I missed the second call to the virtual `GetQueryMaker()` method on the first pass. Let's add another parameter `bool logQueries` to this overload. It can be passed from the other constructor as `StringComparer.OrdinalIgnoreCase.Equals(config?.Get("log.queries", "false") ?? "false", "true")` which will bypass if `config` is `null`. Then we can change the original block to ```c# if (logQueries) { Console.WriteLine("------------> queries:"); Console.WriteLine(GetQueryMaker(new SearchTask(this)).PrintQueries()); } ``` Essentially, the constructor parameter overrides the `config` setting. ########## src/Lucene.Net.Benchmark/ByTask/Tasks/ReadTask.cs: ########## @@ -61,6 +64,14 @@ protected ReadTask(PerfRunData runData) // LUCENENET: CA1012: Abstract types sho } } + // LUCENENET specific - added this constructor to allow subclasses to initialize it + // without having to call constructor that makes a virtual method call + protected ReadTask(PerfRunData runData, IQueryMaker queryMaker) Review Comment: Let's fence this overload with `#nullable enable` and `#nullable restore` so we can change the signature to `protected ReadTask(PerfRunData runData, IQueryMaker? queryMaker)`. There is a lot of work to do to make the whole project use nullable reference types, but if we are going to be adding parameters that allow null, we should get ahead of this. ########## src/Lucene.Net.Benchmark/ByTask/PerfRunData.cs: ########## @@ -98,7 +99,15 @@ public class PerfRunData : IDisposable private readonly IDictionary<string, object> perfObjects = new Dictionary<string, object>(); // constructor - public PerfRunData(Config config) + public PerfRunData(Config config) : this(config, true) Review Comment: Let's add a label to improve readability in the case of `true` ```c# : this(config, performReinit: true, string.Equals("log. Queries", "false") ?? "false", "true", StringComparison.OrdinalIgnoreCase)) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org