[#79] DeliveryAdminWindow: Cache modifiers
This commit is contained in:
@@ -113,10 +113,10 @@ namespace Elwig.Helpers {
|
||||
.Where(l => includePredicate || !l.IsPredicate)
|
||||
.OrderBy(l => l.MinKmw));
|
||||
|
||||
private static readonly Func<AppDbContext, int, bool, IAsyncEnumerable<Modifier>> _compiledQueryModifiers =
|
||||
EF.CompileAsyncQuery<AppDbContext, int, bool, Modifier>((ctx, year, incudeNotActive) => ctx.Modifiers
|
||||
.Where(m => m.Year == year && (incudeNotActive || m.IsActive))
|
||||
.OrderBy(m => m.Ordering).ThenBy(m => m.Name));
|
||||
private static readonly Func<AppDbContext, int?, bool, IAsyncEnumerable<Modifier>> _compiledQueryModifiers =
|
||||
EF.CompileAsyncQuery<AppDbContext, int?, bool, Modifier>((ctx, year, incudeNotActive) => ctx.Modifiers
|
||||
.Where(m => (year == null || m.Year == year) && (incudeNotActive || m.IsActive))
|
||||
.OrderBy(m => m.Year).ThenBy(m => m.Ordering).ThenBy(m => m.Name));
|
||||
|
||||
private static readonly Func<AppDbContext, int?, bool, IAsyncEnumerable<Member>> _compiledQueryMembers =
|
||||
EF.CompileAsyncQuery<AppDbContext, int?, bool, Member>((ctx, mgnr, includeNotActive) => ctx.Members
|
||||
@@ -333,7 +333,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<Modifier> FetchModifiers(int? year, bool incudeNotActive = true) {
|
||||
return _compiledQueryModifiers.Invoke(this, year ?? 0, incudeNotActive);
|
||||
return _compiledQueryModifiers.Invoke(this, year, incudeNotActive);
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<Member> FetchMembers(int? mgnr = null, bool includeNotActive = false, bool includeContactInfo = false) {
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Elwig.Windows {
|
||||
private async Task ModifiersInitEditing(AppDbContext ctx) {
|
||||
SeasonList.IsEnabled = false;
|
||||
var year = (SeasonList.SelectedItem as Season)?.Year;
|
||||
_modList = new(await ctx.FetchModifiers(year).ToListAsync());
|
||||
_modList = new(await ctx.FetchModifiers(year ?? 0).ToListAsync());
|
||||
_mods = _modList.ToDictionary(m => m.ModId, m => (string?)m.ModId);
|
||||
_modIds = _modList.ToDictionary(m => m, m => m.ModId);
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, _modList);
|
||||
@@ -31,7 +31,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private async Task ModifiersFinishEditing(AppDbContext ctx) {
|
||||
var year = (SeasonList.SelectedItem as Season)?.Year;
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.FetchModifiers(year).ToListAsync());
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.FetchModifiers(year ?? 0).ToListAsync());
|
||||
_modList = null;
|
||||
_mods = null;
|
||||
_modIds = null;
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace Elwig.Windows {
|
||||
.OrderBy(t => t.VtrgId)
|
||||
.ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(WineCultivationList, await ctx.FetchWineCultivations().ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.FetchModifiers(year).ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.FetchModifiers(year ?? 0).ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
|
||||
}
|
||||
|
||||
protected override void UpdateButtons() {
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace Elwig.Windows {
|
||||
private readonly Button[] WeighingButtons;
|
||||
|
||||
private List<WineQualLevel> WineQualityLevels = [];
|
||||
private Dictionary<int, List<Modifier>> Modifiers = [];
|
||||
|
||||
public DeliveryAdminWindow(bool receipt = false) {
|
||||
InitializeComponent();
|
||||
@@ -506,7 +507,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
var attributes = await ctx.FetchWineAttributes(!IsCreating).ToListAsync();
|
||||
var modifiers = await ctx.FetchModifiers(year, !IsCreating).ToListAsync();
|
||||
Modifiers = await ctx.FetchModifiers(null).GroupBy(m => m.Year).ToDictionaryAsync(g => g.Key, g => g.ToList());
|
||||
|
||||
var font = new FontFamily("Segoe MDL2 Assets");
|
||||
Menu_BulkAction_SetAttribute.Items.Clear();
|
||||
@@ -526,7 +527,7 @@ namespace Elwig.Windows {
|
||||
|
||||
Menu_BulkAction_AddModifier.Items.Clear();
|
||||
Menu_BulkAction_RemoveModifier.Items.Clear();
|
||||
foreach (var mod in modifiers) {
|
||||
foreach (var mod in Modifiers.GetValueOrDefault(ViewModel.SelectedDelivery?.Year ?? 0, []).Where(m => m.IsActive || !IsCreating)) {
|
||||
var i1 = new MenuItem {
|
||||
Header = mod.Name,
|
||||
};
|
||||
@@ -552,7 +553,7 @@ namespace Elwig.Windows {
|
||||
ControlUtils.RenewItemsSource(CultivationInput, cultList, null, ControlUtils.RenewSourceDefault.First);
|
||||
WineQualityLevels = await ctx.FetchWineQualityLevels().ToListAsync();
|
||||
ControlUtils.RenewItemsSource(WineQualityLevelInput, WineQualityLevels);
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, modifiers);
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, Modifiers.GetValueOrDefault(year, []).Where(m => m.IsActive || !IsCreating).ToList());
|
||||
var origins = await ctx.WineOrigins.ToListAsync();
|
||||
origins.ForEach(o => { origins.FirstOrDefault(p => p.HkId == o.ParentHkId)?.Children.Add(o); });
|
||||
origins = [.. origins.OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId)];
|
||||
@@ -579,12 +580,11 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async Task RefreshDeliveryParts() {
|
||||
using var ctx = new AppDbContext();
|
||||
if (DeliveryList.SelectedItem is Delivery d) {
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, await ctx.FetchModifiers(d.Year, !IsCreating).ToListAsync());
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, Modifiers.GetValueOrDefault(d.Year, []).Where(m => m.IsActive || !IsCreating).ToList());
|
||||
ControlUtils.RenewItemsSource(DeliveryPartList, d.Parts, DeliveryPartList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
||||
} else {
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, await ctx.FetchModifiers(ViewModel.FilterSeason, !IsCreating).ToListAsync());
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, Modifiers.GetValueOrDefault(ViewModel.FilterSeason ?? 0, []).Where(m => m.IsActive || !IsCreating).ToList());
|
||||
DeliveryPartList.ItemsSource = null;
|
||||
}
|
||||
}
|
||||
@@ -913,7 +913,7 @@ namespace Elwig.Windows {
|
||||
var attrList = await ctx.FetchWineAttributes(false).Cast<object>().ToListAsync();
|
||||
attrList.Insert(0, new NullItem(""));
|
||||
ControlUtils.RenewItemsSource(AttributeInput, attrList, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, await ctx.FetchModifiers(ViewModel.FilterSeason, false).ToListAsync());
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, Modifiers.GetValueOrDefault(ViewModel.FilterSeason ?? 0, []).Where(m => m.IsActive).ToList());
|
||||
ControlUtils.RenewItemsSource(MemberInput, await ctx.FetchMembers(includeNotActive: !ViewModel.IsReceipt, includeContactInfo: true).ToListAsync());
|
||||
IsCreating = true;
|
||||
DeliveryList.IsEnabled = false;
|
||||
|
||||
Reference in New Issue
Block a user