This commit is contained in:
@@ -63,6 +63,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
//request cache for viz fields
|
//request cache for viz fields
|
||||||
private VizCache vc = new VizCache();
|
private VizCache vc = new VizCache();
|
||||||
|
private ObjectCache oc = new ObjectCache();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗
|
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗
|
||||||
@@ -5811,17 +5812,42 @@ namespace AyaNova.Biz
|
|||||||
if (calculateTotalsOnly == false)
|
if (calculateTotalsOnly == false)
|
||||||
{
|
{
|
||||||
if (o.UserId != null)
|
if (o.UserId != null)
|
||||||
o.UserViz = await ct.User.AsNoTracking().Where(x => x.Id == o.UserId).Select(x => x.Name).FirstOrDefaultAsync();
|
{
|
||||||
|
if (!vc.Has("user", o.UserId))
|
||||||
|
{
|
||||||
|
vc.Add(await ct.User.AsNoTracking().Where(x => x.Id == o.UserId).Select(x => x.Name).FirstOrDefaultAsync(), "user", o.UserId);
|
||||||
|
}
|
||||||
|
o.UserViz = vc.Get("user", o.UserId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
TravelRate Rate = null;
|
TravelRate Rate = null;
|
||||||
if (o.TravelRateId != null)
|
if (o.TravelRateId != null)
|
||||||
|
{
|
||||||
|
if (!oc.Has("travelrate", o.TravelRateId))
|
||||||
{
|
{
|
||||||
Rate = await ct.TravelRate.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.TravelRateId);
|
Rate = await ct.TravelRate.AsNoTracking().FirstOrDefaultAsync(x => x.Id == o.TravelRateId);
|
||||||
|
oc.Add(Rate, "travelrate", o.TravelRateId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Rate = (TravelRate)oc.Get("travelrate", o.TravelRateId);
|
||||||
|
|
||||||
o.TravelRateViz = Rate.Name;
|
o.TravelRateViz = Rate.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaxCode Tax = null;
|
TaxCode Tax = null;
|
||||||
if (o.TaxCodeSaleId != null)
|
if (o.TaxCodeSaleId != null)
|
||||||
|
{
|
||||||
|
if (!oc.Has("tax", o.TaxCodeSaleId))
|
||||||
|
{
|
||||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxCodeSaleId);
|
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.TaxCodeSaleId);
|
||||||
|
oc.Add(Rate, "tax", o.TaxCodeSaleId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Tax = (TaxCode)oc.Get("tax", o.TaxCodeSaleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (Tax != null)
|
if (Tax != null)
|
||||||
o.TaxCodeViz = Tax.Name;
|
o.TaxCodeViz = Tax.Name;
|
||||||
|
|
||||||
|
|||||||
45
server/AyaNova/util/ObjectCache.cs
Normal file
45
server/AyaNova/util/ObjectCache.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AyaNova.Util
|
||||||
|
{
|
||||||
|
//Object cache - used by biz objects during get report data to temporarily cache values from database for single request
|
||||||
|
//saves db calls and formatting
|
||||||
|
internal class ObjectCache
|
||||||
|
{
|
||||||
|
private Dictionary<string, object> _cache = new Dictionary<string, object>();
|
||||||
|
// internal ObjectCache()
|
||||||
|
// {
|
||||||
|
// System.Diagnostics.Debug.WriteLine("constructing objectcache");
|
||||||
|
// }
|
||||||
|
internal void Add(object value, string key, long? id = 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
_cache[$"{key}{id}"] = value;
|
||||||
|
// System.Diagnostics.Debug.WriteLine($"ADD {key}{id} - {value}");
|
||||||
|
}
|
||||||
|
internal object Get(string key, long? id = 0)
|
||||||
|
{
|
||||||
|
object value = null;
|
||||||
|
if (_cache.TryGetValue($"{key}{id}", out value))
|
||||||
|
{
|
||||||
|
//System.Diagnostics.Debug.WriteLine($"get cache hit {key}{id}");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.Diagnostics.Debug.WriteLine($"get cache miss {key}{id}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool Has(string key, long? id = 0)
|
||||||
|
{
|
||||||
|
return _cache.ContainsKey($"{key}{id}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}//eoc
|
||||||
|
|
||||||
|
}//eons
|
||||||
Reference in New Issue
Block a user