Cache resolved store items in HTTP context

This commit is contained in:
Dennis Reimann
2021-12-16 17:37:19 +01:00
committed by Andrew Camilleri
parent 38ff3e5e89
commit 3a59e2a5c4
13 changed files with 273 additions and 231 deletions

View File

@@ -75,8 +75,7 @@ namespace BTCPayServer.Controllers
public string CustomTipText { get; set; } = CUSTOM_TIP_TEXT_DEF;
public static readonly int[] CUSTOM_TIP_PERCENTAGES_DEF = new int[] { 15, 18, 20 };
public int[] CustomTipPercentages { get; set; } = CUSTOM_TIP_PERCENTAGES_DEF;
public string CustomCSSLink { get; set; }
public string EmbeddedCSS { get; set; }
@@ -88,21 +87,20 @@ namespace BTCPayServer.Controllers
}
[HttpGet("{appId}/settings/pos")]
public async Task<IActionResult> UpdatePointOfSale(string appId)
public IActionResult UpdatePointOfSale(string appId)
{
var app = await GetOwnedApp(appId, AppType.PointOfSale);
if (app == null)
if (CurrentApp == null)
return NotFound();
var settings = app.GetSettings<PointOfSaleSettings>();
var settings = CurrentApp.GetSettings<PointOfSaleSettings>();
settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView;
settings.EnableShoppingCart = false;
var vm = new UpdatePointOfSaleViewModel
{
Id = appId,
StoreId = app.StoreDataId,
StoreName = app.StoreData?.StoreName,
AppName = app.Name,
StoreId = CurrentApp.StoreDataId,
StoreName = CurrentApp.StoreData?.StoreName,
AppName = CurrentApp.Name,
Title = settings.Title,
DefaultView = settings.DefaultView,
ShowCustomAmount = settings.ShowCustomAmount,
@@ -119,7 +117,7 @@ namespace BTCPayServer.Controllers
Description = settings.Description,
NotificationUrl = settings.NotificationUrl,
RedirectUrl = settings.RedirectUrl,
SearchTerm = $"storeid:{app.StoreDataId}",
SearchTerm = $"storeid:{CurrentApp.StoreDataId}",
RedirectAutomatically = settings.RedirectAutomatically.HasValue ? settings.RedirectAutomatically.Value ? "true" : "false" : "",
RequiresRefundEmail = settings.RequiresRefundEmail
};
@@ -164,14 +162,13 @@ namespace BTCPayServer.Controllers
[HttpPost("{appId}/settings/pos")]
public async Task<IActionResult> UpdatePointOfSale(string appId, UpdatePointOfSaleViewModel vm)
{
var app = await GetOwnedApp(appId, AppType.PointOfSale);
if (app == null)
if (CurrentApp == null)
return NotFound();
if (!ModelState.IsValid)
{
return View(vm);
}
vm.Currency = await GetStoreDefaultCurrentIfEmpty(app.StoreDataId, vm.Currency);
vm.Currency = await GetStoreDefaultCurrentIfEmpty(CurrentApp.StoreDataId, vm.Currency);
if (_currencies.GetCurrencyData(vm.Currency, false) == null)
ModelState.AddModelError(nameof(vm.Currency), "Invalid currency");
try
@@ -187,8 +184,8 @@ namespace BTCPayServer.Controllers
return View(vm);
}
app.Name = vm.AppName;
app.SetSettings(new PointOfSaleSettings
CurrentApp.Name = vm.AppName;
CurrentApp.SetSettings(new PointOfSaleSettings
{
Title = vm.Title,
DefaultView = vm.DefaultView,
@@ -209,7 +206,7 @@ namespace BTCPayServer.Controllers
RedirectAutomatically = string.IsNullOrEmpty(vm.RedirectAutomatically) ? (bool?)null : bool.Parse(vm.RedirectAutomatically),
RequiresRefundEmail = vm.RequiresRefundEmail,
});
await _appService.UpdateOrCreateApp(app);
await _appService.UpdateOrCreateApp(CurrentApp);
TempData[WellKnownTempData.SuccessMessage] = "App updated";
return RedirectToAction(nameof(UpdatePointOfSale), new { appId });
}
@@ -220,14 +217,12 @@ namespace BTCPayServer.Controllers
{
return Array.Empty<int>();
}
else
{
// Remove all characters except numeric and comma
Regex charsToDestroy = new Regex(@"[^\d|\" + separator + "]");
list = charsToDestroy.Replace(list, "");
// Remove all characters except numeric and comma
Regex charsToDestroy = new Regex(@"[^\d|\" + separator + "]");
list = charsToDestroy.Replace(list, "");
return list.Split(separator, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
}
return list.Split(separator, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
}
}
}