mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
Use TryGetValue instead of ContainsKey + index access to avoid double lookup (#193)
This PR fixes an issue that is currently causing CI to fail in all pull requests: `Notice: "[CA1854] Prefer a 'TryGetValue' call over a Dictionary indexer access guarded by a 'ContainsKey' check to avoid double lookup" on /home/runner/work/Octobot/Octobot/src/Services/Update/ScheduledEventUpdateService.cs(107,4168)` The issue is resolved by following the advice mentioned in the notice.
This commit is contained in:
parent
c031b66eb4
commit
e65c7a469d
1 changed files with 1 additions and 2 deletions
|
@ -104,14 +104,13 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
||||||
{
|
{
|
||||||
foreach (var @event in events)
|
foreach (var @event in events)
|
||||||
{
|
{
|
||||||
if (!data.ScheduledEvents.ContainsKey(@event.ID.Value))
|
if (!data.ScheduledEvents.TryGetValue(@event.ID.Value, out var eventData))
|
||||||
{
|
{
|
||||||
data.ScheduledEvents.Add(@event.ID.Value,
|
data.ScheduledEvents.Add(@event.ID.Value,
|
||||||
new ScheduledEventData(@event.ID.Value, @event.Name, @event.ScheduledStartTime, @event.Status));
|
new ScheduledEventData(@event.ID.Value, @event.Name, @event.ScheduledStartTime, @event.Status));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var eventData = data.ScheduledEvents[@event.ID.Value];
|
|
||||||
eventData.Name = @event.Name;
|
eventData.Name = @event.Name;
|
||||||
eventData.ScheduledStartTime = @event.ScheduledStartTime;
|
eventData.ScheduledStartTime = @event.ScheduledStartTime;
|
||||||
if (!eventData.ScheduleOnStatusUpdated)
|
if (!eventData.ScheduleOnStatusUpdated)
|
||||||
|
|
Loading…
Reference in a new issue