Skip to content

Commit

Permalink
Add caching of some entities in admin area (categories only now) #173
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Chmir committed Jul 11, 2016
1 parent 8ef9198 commit eb3f963
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using System.Linq;
using System.Web.Mvc;
using Nop.Admin.Extensions;
using Nop.Admin.Helpers;
using Nop.Admin.Models.Catalog;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Discounts;
using Nop.Services.Catalog;
Expand Down Expand Up @@ -50,6 +52,7 @@ public partial class CategoryController : BaseAdminController
private readonly CatalogSettings _catalogSettings;
private readonly IWorkContext _workContext;
private readonly IImportManager _importManager;
private readonly ICacheManager _cacheManager;

#endregion

Expand All @@ -73,7 +76,8 @@ public partial class CategoryController : BaseAdminController
ICustomerActivityService customerActivityService,
CatalogSettings catalogSettings,
IWorkContext workContext,
IImportManager importManager)
IImportManager importManager,
ICacheManager cacheManager)
{
this._categoryService = categoryService;
this._categoryTemplateService = categoryTemplateService;
Expand All @@ -96,6 +100,7 @@ public partial class CategoryController : BaseAdminController
this._catalogSettings = catalogSettings;
this._workContext = workContext;
this._importManager = importManager;
this._cacheManager = cacheManager;
}

#endregion
Expand Down Expand Up @@ -157,15 +162,9 @@ protected virtual void PrepareAllCategoriesModel(CategoryModel model)
Text = "[None]",
Value = "0"
});
var categories = _categoryService.GetAllCategories(showHidden: true);
var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);
foreach (var c in categories)
{
model.AvailableCategories.Add(new SelectListItem
{
Text = c.GetFormattedBreadCrumb(categories),
Value = c.Id.ToString()
});
}
model.AvailableCategories.Add(c);
}

[NonAction]
Expand Down Expand Up @@ -699,9 +698,9 @@ public ActionResult ProductAddPopup(int categoryId)
var model = new CategoryModel.AddCategoryProductModel();
//categories
model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
var categories = _categoryService.GetAllCategories(showHidden: true);
var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);
foreach (var c in categories)
model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() });
model.AvailableCategories.Add(c);

//manufacturers
model.AvailableManufacturers.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using System.Linq;
using System.Web.Mvc;
using Nop.Admin.Extensions;
using Nop.Admin.Helpers;
using Nop.Admin.Models.Customers;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Customers;
using Nop.Services.Catalog;
Expand Down Expand Up @@ -34,6 +36,7 @@ public partial class CustomerRoleController : BaseAdminController
private readonly IStoreService _storeService;
private readonly IVendorService _vendorService;
private readonly IWorkContext _workContext;
private readonly ICacheManager _cacheManager;

#endregion

Expand All @@ -48,7 +51,8 @@ public partial class CustomerRoleController : BaseAdminController
IManufacturerService manufacturerService,
IStoreService storeService,
IVendorService vendorService,
IWorkContext workContext)
IWorkContext workContext,
ICacheManager cacheManager)
{
this._customerService = customerService;
this._localizationService = localizationService;
Expand All @@ -60,6 +64,7 @@ public partial class CustomerRoleController : BaseAdminController
this._storeService = storeService;
this._vendorService = vendorService;
this._workContext = workContext;
this._cacheManager = cacheManager;
}

#endregion 
Expand Down Expand Up @@ -247,9 +252,9 @@ public ActionResult AssociateProductToCustomerRolePopup()

//categories
model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
var categories = _categoryService.GetAllCategories(showHidden: true);
var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);
foreach (var c in categories)
model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() });
model.AvailableCategories.Add(c);

//manufacturers
model.AvailableManufacturers.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using System.Linq;
using System.Web.Mvc;
using Nop.Admin.Extensions;
using Nop.Admin.Helpers;
using Nop.Admin.Models.Discounts;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Directory;
using Nop.Core.Domain.Discounts;
Expand Down Expand Up @@ -45,6 +47,7 @@ public partial class DiscountController : BaseAdminController
private readonly IVendorService _vendorService;
private readonly IOrderService _orderService;
private readonly IPriceFormatter _priceFormatter;
private readonly ICacheManager _cacheManager;

#endregion

Expand All @@ -65,7 +68,8 @@ public partial class DiscountController : BaseAdminController
IStoreService storeService,
IVendorService vendorService,
IOrderService orderService,
IPriceFormatter priceFormatter)
IPriceFormatter priceFormatter,
ICacheManager cacheManager)
{
this._discountService = discountService;
this._localizationService = localizationService;
Expand All @@ -83,6 +87,7 @@ public partial class DiscountController : BaseAdminController
this._vendorService = vendorService;
this._orderService = orderService;
this._priceFormatter = priceFormatter;
this._cacheManager = cacheManager;
}

#endregion
Expand Down Expand Up @@ -465,9 +470,9 @@ public ActionResult ProductAddPopup(int discountId)
var model = new DiscountModel.AddProductToDiscountModel();
//categories
model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
var categories = _categoryService.GetAllCategories(showHidden: true);
var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);
foreach (var c in categories)
model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() });
model.AvailableCategories.Add(c);

//manufacturers
model.AvailableManufacturers.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System.Linq;
using System.Web.Mvc;
using Nop.Admin.Extensions;
using Nop.Admin.Helpers;
using Nop.Admin.Models.Catalog;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Discounts;
using Nop.Services.Catalog;
Expand Down Expand Up @@ -51,6 +53,7 @@ public partial class ManufacturerController : BaseAdminController
private readonly CatalogSettings _catalogSettings;
private readonly IWorkContext _workContext;
private readonly IImportManager _importManager;
private readonly ICacheManager _cacheManager;

#endregion

Expand All @@ -76,7 +79,8 @@ public partial class ManufacturerController : BaseAdminController
IPermissionService permissionService,
CatalogSettings catalogSettings,
IWorkContext workContext,
IImportManager importManager)
IImportManager importManager,
ICacheManager cacheManager)
{
this._categoryService = categoryService;
this._manufacturerTemplateService = manufacturerTemplateService;
Expand All @@ -99,6 +103,7 @@ public partial class ManufacturerController : BaseAdminController
this._catalogSettings = catalogSettings;
this._workContext = workContext;
this._importManager = importManager;
this._cacheManager = cacheManager;
}

#endregion
Expand Down Expand Up @@ -675,9 +680,9 @@ public ActionResult ProductAddPopup(int manufacturerId)
var model = new ManufacturerModel.AddManufacturerProductModel();
//categories
model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
var categories = _categoryService.GetAllCategories(showHidden: true);
var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);
foreach (var c in categories)
model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() });
model.AvailableCategories.Add(c);

//manufacturers
model.AvailableManufacturers.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using System.Linq;
using System.Web.Mvc;
using Nop.Admin.Extensions;
using Nop.Admin.Helpers;
using Nop.Admin.Models.Orders;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common;
using Nop.Core.Domain.Customers;
Expand Down Expand Up @@ -85,6 +87,7 @@ public partial class OrderController : BaseAdminController
private readonly IAffiliateService _affiliateService;
private readonly IPictureService _pictureService;
private readonly ICustomerActivityService _customerActivityService;
private readonly ICacheManager _cacheManager;

private readonly OrderSettings _orderSettings;
private readonly CurrencySettings _currencySettings;
Expand Down Expand Up @@ -138,6 +141,7 @@ public partial class OrderController : BaseAdminController
IAffiliateService affiliateService,
IPictureService pictureService,
ICustomerActivityService customerActivityService,
ICacheManager cacheManager,
OrderSettings orderSettings,
CurrencySettings currencySettings,
TaxSettings taxSettings,
Expand Down Expand Up @@ -186,6 +190,7 @@ public partial class OrderController : BaseAdminController
this._affiliateService = affiliateService;
this._pictureService = pictureService;
this._customerActivityService = customerActivityService;
this._cacheManager = cacheManager;
this._orderSettings = orderSettings;
this._currencySettings = currencySettings;
this._taxSettings = taxSettings;
Expand Down Expand Up @@ -2480,9 +2485,9 @@ public ActionResult AddProductToOrder(int orderId)
model.OrderId = orderId;
//categories
model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
var categories = _categoryService.GetAllCategories(showHidden: true);
var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);
foreach (var c in categories)
model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() });
model.AvailableCategories.Add(c);

//manufacturers
model.AvailableManufacturers.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
Expand Down Expand Up @@ -3865,9 +3870,9 @@ public ActionResult BestsellersReport()

//categories
model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
var categories = _categoryService.GetAllCategories(showHidden: true);
var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);
foreach (var c in categories)
model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() });
model.AvailableCategories.Add(c);

//manufacturers
model.AvailableManufacturers.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
Expand Down

0 comments on commit eb3f963

Please sign in to comment.