diff --git a/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation.cs b/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation.cs index 6aa6afc40..f9e73105d 100644 --- a/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation.cs +++ b/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation.cs @@ -177,7 +177,6 @@ public CL_MainChanges GetAllChanges(DateTime date, int userID) var changes = ChangeTracker.GetChainedChanges( new List> { - RepoFactory.FilterPreset.GetChangeTracker(), RepoFactory.AnimeGroup.GetChangeTracker(), RepoFactory.AnimeGroup_User.GetChangeTracker(userID), RepoFactory.AnimeSeries.GetChangeTracker(), @@ -186,46 +185,45 @@ public CL_MainChanges GetAllChanges(DateTime date, int userID) var legacyConverter = HttpContext.RequestServices.GetRequiredService(); c.Filters = new CL_Changes { - ChangedItems = legacyConverter.ToClient(changes[0].ChangedItems.Select(a => RepoFactory.FilterPreset.GetByID(a)).ToList(), userID) - .Select(a => a.Value) + ChangedItems = legacyConverter.ToClient(RepoFactory.FilterPreset.GetAll(), userID) .Where(a => a != null) .ToList(), - RemovedItems = changes[0].RemovedItems.ToList(), - LastChange = changes[0].LastChange + RemovedItems = new List(), + LastChange = DateTime.Now }; c.Groups = new CL_Changes(); - changes[1].ChangedItems.UnionWith(changes[2].ChangedItems); - changes[1].ChangedItems.UnionWith(changes[2].RemovedItems); - if (changes[2].LastChange > changes[1].LastChange) + changes[0].ChangedItems.UnionWith(changes[1].ChangedItems); + changes[0].ChangedItems.UnionWith(changes[1].RemovedItems); + if (changes[1].LastChange > changes[0].LastChange) { - changes[1].LastChange = changes[2].LastChange; + changes[0].LastChange = changes[1].LastChange; } - c.Groups.ChangedItems = changes[1] + c.Groups.ChangedItems = changes[0] .ChangedItems.Select(a => RepoFactory.AnimeGroup.GetByID(a)) .Where(a => a != null) .Select(a => a.GetUserContract(userID)) .ToList(); - c.Groups.RemovedItems = changes[1].RemovedItems.ToList(); - c.Groups.LastChange = changes[1].LastChange; + c.Groups.RemovedItems = changes[0].RemovedItems.ToList(); + c.Groups.LastChange = changes[0].LastChange; c.Series = new CL_Changes(); - changes[3].ChangedItems.UnionWith(changes[4].ChangedItems); - changes[3].ChangedItems.UnionWith(changes[4].RemovedItems); - if (changes[4].LastChange > changes[3].LastChange) + changes[2].ChangedItems.UnionWith(changes[3].ChangedItems); + changes[2].ChangedItems.UnionWith(changes[3].RemovedItems); + if (changes[3].LastChange > changes[2].LastChange) { - changes[3].LastChange = changes[4].LastChange; + changes[2].LastChange = changes[3].LastChange; } - c.Series.ChangedItems = changes[3] + c.Series.ChangedItems = changes[2] .ChangedItems.Select(a => RepoFactory.AnimeSeries.GetByID(a)) .Where(a => a != null) .Select(a => a.GetUserContract(userID)) .ToList(); - c.Series.RemovedItems = changes[3].RemovedItems.ToList(); - c.Series.LastChange = changes[3].LastChange; + c.Series.RemovedItems = changes[2].RemovedItems.ToList(); + c.Series.LastChange = changes[2].LastChange; c.LastChange = c.Filters.LastChange; if (c.Groups.LastChange > c.LastChange) { @@ -252,13 +250,11 @@ public CL_Changes GetGroupFilterChanges(DateTime date) try { var legacyConverter = HttpContext.RequestServices.GetRequiredService(); - var changes = RepoFactory.FilterPreset.GetChangeTracker().GetChanges(date); - c.ChangedItems = legacyConverter.ToClient(changes.ChangedItems.Select(a => RepoFactory.FilterPreset.GetByID(a)).ToList()) - .Select(a => a.Value) + c.ChangedItems = legacyConverter.ToClient(RepoFactory.FilterPreset.GetAll()) .Where(a => a != null) .ToList(); - c.RemovedItems = changes.RemovedItems.ToList(); - c.LastChange = changes.LastChange; + c.RemovedItems = new List(); + c.LastChange = DateTime.Now; } catch (Exception ex) { diff --git a/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation_Entities.cs b/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation_Entities.cs index 0ffa64497..2e556c70b 100644 --- a/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation_Entities.cs +++ b/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation_Entities.cs @@ -3118,7 +3118,7 @@ public List GetAllGroupFiltersExtended(int userID) var legacyConverter = HttpContext.RequestServices.GetRequiredService(); gfs = legacyConverter.ToClient(allGfs).Select(a => new CL_GroupFilterExtended { - GroupFilter = a.Value, GroupCount = a.Value.Groups[userID].Count + GroupFilter = a, GroupCount = a.Groups[userID].Count }).ToList(); } catch (Exception ex) @@ -3147,7 +3147,7 @@ public List GetGroupFiltersExtended(int userID, int gfpa var legacyConverter = HttpContext.RequestServices.GetRequiredService(); gfs = legacyConverter.ToClient(allGfs).Select(a => new CL_GroupFilterExtended { - GroupFilter = a.Value, GroupCount = a.Value.Groups.FirstOrDefault().Value.Count + GroupFilter = a, GroupCount = a.Groups.FirstOrDefault().Value.Count }).ToList(); } catch (Exception ex) @@ -3172,7 +3172,6 @@ public List GetAllGroupFilters() var legacyConverter = HttpContext.RequestServices.GetRequiredService(); gfs = legacyConverter.ToClient(allGfs) - .Select(a => a.Value) .Where(a => a != null) .ToList(); } @@ -3197,7 +3196,6 @@ public List GetGroupFilters(int gfparentid = 0) logger.Info("GetAllGroupFilters (Database) in {0} ms", ts.TotalMilliseconds); var legacyConverter = HttpContext.RequestServices.GetRequiredService(); gfs = legacyConverter.ToClient(allGfs) - .Select(a => a.Value) .Where(a => a != null) .ToList(); } diff --git a/Shoko.Server/Filters/Legacy/LegacyFilterConverter.cs b/Shoko.Server/Filters/Legacy/LegacyFilterConverter.cs index db2972841..73973a5d0 100644 --- a/Shoko.Server/Filters/Legacy/LegacyFilterConverter.cs +++ b/Shoko.Server/Filters/Legacy/LegacyFilterConverter.cs @@ -100,20 +100,20 @@ public CL_GroupFilter ToClient(FilterPreset filter) return contract; } - public Dictionary ToClient(IReadOnlyList filters, int? userID = null) + public List ToClient(IReadOnlyList filters, int? userID = null) { - var result = new Dictionary(); + var result = new List(); var userFilters = filters.Where(a => a?.Expression?.UserDependent ?? false).ToList(); var otherFilters = filters.Except(userFilters).ToList(); // batch evaluate each list, then build the mappings - if (userFilters.Count > 0) SetUserFilters(userID, userFilters, result); - if (otherFilters.Count > 0) SetOtherFilters(otherFilters, result); + if (userFilters.Count > 0) result.AddRange(SetUserFilters(userID, userFilters)); + if (otherFilters.Count > 0) result.AddRange(SetOtherFilters(otherFilters)); return result; } - private void SetOtherFilters(List otherFilters, Dictionary result) + private List SetOtherFilters(List otherFilters) { var results = _evaluator.BatchEvaluateFilters(otherFilters, null, true); @@ -132,7 +132,7 @@ private void SetOtherFilters(List otherFilters, Dictionary condition.GroupFilterID = filter.FilterPresetID); - return (Filter: filter, new CL_GroupFilter + return new CL_GroupFilter { GroupFilterID = filter.FilterPresetID, GroupFilterName = filter.Name, @@ -149,13 +149,10 @@ private void SetOtherFilters(List otherFilters, Dictionary() : RepoFactory.FilterPreset.GetByParentID(filter.FilterPresetID).Select(a => a.FilterPresetID).ToHashSet() - }); - }); + }; + }).ToList(); - foreach (var (filter, model) in models) - { - result[filter] = model; - } + return models; } /// @@ -164,7 +161,7 @@ private void SetOtherFilters(List otherFilters, Dictionaryif this is specified, it only calculates one user /// /// - private void SetUserFilters(int? userID, List userFilters, Dictionary result) + private List SetUserFilters(int? userID, List userFilters) { var userResults = userID.HasValue @@ -185,7 +182,7 @@ private void SetUserFilters(int? userID, List userFilters, Diction } LegacyConditionConverter.TryConvertToConditions(filter, out var conditions, out var baseCondition); conditions?.ForEach(condition => condition.GroupFilterID = filter.FilterPresetID); - return (Filter: filter, new CL_GroupFilter + return new CL_GroupFilter { GroupFilterID = filter.FilterPresetID, GroupFilterName = filter.Name, @@ -202,12 +199,9 @@ private void SetUserFilters(int? userID, List userFilters, Diction Childs = filter.FilterPresetID == 0 ? new HashSet() : RepoFactory.FilterPreset.GetByParentID(filter.FilterPresetID).Select(a => a.FilterPresetID).ToHashSet() - }); - }); + }; + }).ToList(); - foreach (var (filter, model) in userModels) - { - result[filter] = model; - } + return userModels; } } diff --git a/Shoko.Server/Repositories/Cached/FilterPresetRepository.cs b/Shoko.Server/Repositories/Cached/FilterPresetRepository.cs index 49480711d..a08b2a783 100644 --- a/Shoko.Server/Repositories/Cached/FilterPresetRepository.cs +++ b/Shoko.Server/Repositories/Cached/FilterPresetRepository.cs @@ -27,19 +27,6 @@ namespace Shoko.Server.Repositories.Cached; public class FilterPresetRepository : BaseCachedRepository { private PocoIndex Parents; - private readonly ChangeTracker Changes = new(); - - public FilterPresetRepository() - { - EndSaveCallback = obj => - { - Changes.AddOrUpdate(obj.FilterPresetID); - }; - EndDeleteCallback = obj => - { - Changes.Remove(obj.FilterPresetID); - }; - } protected override int SelectKey(FilterPreset entity) { @@ -48,7 +35,6 @@ protected override int SelectKey(FilterPreset entity) public override void PopulateIndexes() { - Changes.AddOrUpdateRange(Cache.Keys); Parents = Cache.CreateIndex(a => a.ParentFilterPresetID ?? 0); } @@ -485,9 +471,4 @@ public List GetTimeDependentFilters() { return ReadLock(() => GetAll().Where(a => a.Expression.TimeDependent).ToList()); } - - public ChangeTracker GetChangeTracker() - { - return Changes; - } }