Skip to content

Commit

Permalink
Updated Filter method to iterate filters only once
Browse files Browse the repository at this point in the history
  • Loading branch information
jschick04 authored and bill-long committed May 8, 2024
1 parent cc1258e commit 676d694
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/EventLogExpert.UI/FilterMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using EventLogExpert.Eventing.Models;
using EventLogExpert.UI.Models;
using System.Collections.Immutable;
using System.Linq.Dynamic.Core;
using System.Text;

Expand Down Expand Up @@ -41,15 +40,23 @@ public static Dictionary<string, FilterGroupData> AddFilterGroup(
return group;
}

public static bool Filter(this DisplayEventModel? @event, ImmutableList<FilterModel> filters)
public static bool Filter(this DisplayEventModel? @event, IEnumerable<FilterModel> filters)
{
if (@event is null) { return false; }

if (filters.IsEmpty) { return true; }
bool isEmpty = true;
bool isFiltered = false;

if (filters.Any(filter => filter.IsExcluded && filter.Comparison.Expression(@event))) { return false; }
foreach (var filter in filters)
{
if (filter.IsExcluded && filter.Comparison.Expression(@event)) { return false; }

if (!filter.IsExcluded) { isEmpty = false; }

if (!filter.IsExcluded && filter.Comparison.Expression(@event)) { isFiltered = true; }
}

return filters.All(filter => filter.IsExcluded) || filters.Any(filter => !filter.IsExcluded && filter.Comparison.Expression(@event));
return isEmpty || isFiltered;
}

public static IDictionary<EventLogId, IEnumerable<DisplayEventModel>> FilterActiveLogs(
Expand Down

0 comments on commit 676d694

Please sign in to comment.