From 61b77a85f4557481240df904e2e84f5b47a85d48 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 14 Nov 2023 12:26:02 +0900 Subject: [PATCH 1/3] Remove local disable ENVVARs for processors --- .../Processors/MedalProcessor.cs | 5 ----- .../Processors/UserTotalPerformanceProcessor.cs | 5 ----- 2 files changed, 10 deletions(-) diff --git a/osu.Server.Queues.ScoreStatisticsProcessor/Processors/MedalProcessor.cs b/osu.Server.Queues.ScoreStatisticsProcessor/Processors/MedalProcessor.cs index 74fb2e3f..15e128ba 100644 --- a/osu.Server.Queues.ScoreStatisticsProcessor/Processors/MedalProcessor.cs +++ b/osu.Server.Queues.ScoreStatisticsProcessor/Processors/MedalProcessor.cs @@ -20,8 +20,6 @@ namespace osu.Server.Queues.ScoreStatisticsProcessor.Processors [UsedImplicitly] public class MedalProcessor : IProcessor { - private static readonly bool process_user_medals = Environment.GetEnvironmentVariable("PROCESS_USER_MEDALS") != "0"; - private static readonly List medal_awarders = new List(); private ImmutableArray? availableMedals; @@ -49,9 +47,6 @@ public void RevertFromUserStats(SoloScoreInfo score, UserStats userStats, int pr public void ApplyToUserStats(SoloScoreInfo score, UserStats userStats, MySqlConnection conn, MySqlTransaction transaction) { - if (!process_user_medals) - return; - int[] alreadyAchieved = conn.Query("SELECT achievement_id FROM osu_user_achievements WHERE user_id = @userId", new { userId = score.UserID diff --git a/osu.Server.Queues.ScoreStatisticsProcessor/Processors/UserTotalPerformanceProcessor.cs b/osu.Server.Queues.ScoreStatisticsProcessor/Processors/UserTotalPerformanceProcessor.cs index 8cf96c95..263aa1cd 100644 --- a/osu.Server.Queues.ScoreStatisticsProcessor/Processors/UserTotalPerformanceProcessor.cs +++ b/osu.Server.Queues.ScoreStatisticsProcessor/Processors/UserTotalPerformanceProcessor.cs @@ -25,8 +25,6 @@ public class UserTotalPerformanceProcessor : IProcessor private long lastStoreRefresh; - private static readonly bool process_user_totals = Environment.GetEnvironmentVariable("PROCESS_USER_TOTALS") != "0"; - // This processor needs to run after the score's PP value has been processed. public int Order => ScorePerformanceProcessor.ORDER + 1; @@ -38,9 +36,6 @@ public void RevertFromUserStats(SoloScoreInfo score, UserStats userStats, int pr public void ApplyToUserStats(SoloScoreInfo score, UserStats userStats, MySqlConnection conn, MySqlTransaction transaction) { - if (!process_user_totals) - return; - var dbInfo = LegacyDatabaseHelper.GetRulesetSpecifics(score.RulesetID); int warnings = conn.QuerySingleOrDefault($"SELECT `user_warnings` FROM {dbInfo.UsersTable} WHERE `user_id` = @UserId", new From 052fe4f71da9a86f20eb3eb265b87e6d3f693445 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 14 Nov 2023 12:46:10 +0900 Subject: [PATCH 2/3] Add the ability to specify processors to disable in queue `ctor` --- .../ScoreStatisticsQueueProcessor.cs | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/osu.Server.Queues.ScoreStatisticsProcessor/ScoreStatisticsQueueProcessor.cs b/osu.Server.Queues.ScoreStatisticsProcessor/ScoreStatisticsQueueProcessor.cs index feb286a7..cdea77fe 100644 --- a/osu.Server.Queues.ScoreStatisticsProcessor/ScoreStatisticsQueueProcessor.cs +++ b/osu.Server.Queues.ScoreStatisticsProcessor/ScoreStatisticsQueueProcessor.cs @@ -10,6 +10,7 @@ using Dapper; using Dapper.Contrib.Extensions; using MySqlConnector; +using osu.Framework.Extensions.TypeExtensions; using osu.Game.Online.API.Requests.Responses; using osu.Game.Rulesets; using osu.Server.QueueProcessor; @@ -40,13 +41,14 @@ public class ScoreStatisticsQueueProcessor : QueueProcessor private readonly ElasticQueueProcessor elasticQueueProcessor = new ElasticQueueProcessor(); - public ScoreStatisticsQueueProcessor() + public ScoreStatisticsQueueProcessor(string[]? disabledProcessors = null) : base(new QueueConfiguration { InputQueueName = "score-statistics" }) { DapperExtensions.InstallDateTimeOffsetMapper(); - // add each processor automagically. - foreach (var t in typeof(ScoreStatisticsQueueProcessor).Assembly.GetTypes().Where(t => !t.IsInterface && typeof(IProcessor).IsAssignableFrom(t))) + List enabledTypes = createProcessors(disabledProcessors); + + foreach (var t in enabledTypes) { if (Activator.CreateInstance(t) is IProcessor processor) processors.Add(processor); @@ -55,6 +57,45 @@ public ScoreStatisticsQueueProcessor() processors = processors.OrderBy(p => p.Order).ToList(); } + private List createProcessors(string[]? disabledProcessors) + { + List enabledTypes = typeof(ScoreStatisticsQueueProcessor) + .Assembly + .GetTypes() + .Where(t => !t.IsInterface && typeof(IProcessor).IsAssignableFrom(t)) + .ToList(); + + List disabledTypes = new List(); + + if (disabledProcessors?.Length > 0) + { + foreach (string s in disabledProcessors) + { + var match = enabledTypes.FirstOrDefault(t => t.ReadableName() == s); + + if (match == null) + throw new ArgumentException($"Could not find matching processor to disable (\"{s}\")"); + + enabledTypes.Remove(match); + disabledTypes.Add(match); + } + } + + Console.WriteLine("Active processors:"); + foreach (var type in enabledTypes) + Console.WriteLine($"- {type.ReadableName()}"); + + Console.WriteLine(); + + Console.WriteLine("Disabled processors:"); + foreach (var type in disabledTypes) + Console.WriteLine($"- {type.ReadableName()}"); + + Console.WriteLine(); + + return enabledTypes; + } + protected override void ProcessResult(ScoreItem item) { if (item.Score.ScoreInfo.LegacyScoreId != null) From 4c41500724e99b850bf5ca217bbc457209fccf59 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 14 Nov 2023 16:58:32 +0900 Subject: [PATCH 3/3] Update watch command to support specifying disables --- .../Commands/Queue/WatchQueueCommand.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/osu.Server.Queues.ScoreStatisticsProcessor/Commands/Queue/WatchQueueCommand.cs b/osu.Server.Queues.ScoreStatisticsProcessor/Commands/Queue/WatchQueueCommand.cs index 5678a287..75023af9 100644 --- a/osu.Server.Queues.ScoreStatisticsProcessor/Commands/Queue/WatchQueueCommand.cs +++ b/osu.Server.Queues.ScoreStatisticsProcessor/Commands/Queue/WatchQueueCommand.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Threading; using System.Threading.Tasks; using McMaster.Extensions.CommandLineUtils; @@ -10,11 +11,18 @@ namespace osu.Server.Queues.ScoreStatisticsProcessor.Commands.Queue [Command("watch", Description = "Begins processing of the queue.")] public class WatchQueueCommand { - private readonly ScoreStatisticsQueueProcessor queue = new ScoreStatisticsQueueProcessor(); + /// + /// A comma-separated list of processors to disable. + /// + [Option("--disable", Description = "A comma-separated list of processors to disable.")] + public string DisabledProcessors { get; set; } = string.Empty; public Task OnExecuteAsync(CancellationToken cancellationToken) { + ScoreStatisticsQueueProcessor queue = new ScoreStatisticsQueueProcessor(DisabledProcessors.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)); + queue.Run(cancellationToken); + return Task.FromResult(0); } }