Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude ContentWidgets layer by default in order to increase performance #8750

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public ActionResult Index(int? layerId, string culture) {

IEnumerable<LayerPart> layers = _widgetsService.GetLayers().OrderBy(x => x.Name).ToList();



Comment on lines +66 to +67
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

if (!layers.Any()) {
Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site."));
return RedirectToAction("AddLayer");
Expand All @@ -84,14 +86,27 @@ public ActionResult Index(int? layerId, string culture) {
string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
string zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;
Comment on lines 86 to 87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
string zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;
var zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
var zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;


var widgets = _widgetsService.GetWidgets();
//Only when "ContentWidgets" layer is explicitly chosen the widgets are listed, not by default (for performance reasons)
IEnumerable<WidgetPart> widgets;
var IdLayerContentWidget = layers.Where(x => x.Name.ToLowerInvariant() == "contentwidgets").Select(x => x.Id).FirstOrDefault();
if (IdLayerContentWidget > 0) {
//Ok the layer exists
var IdsLayers = layers.Where(x => x.Name.ToLowerInvariant() != "contentwidgets").Select(x => x.Id).ToList().ToArray();
if (layerId != null && (int)layerId == IdLayerContentWidget) {
//If ContentWidgets is chosen explicitly then IdsLayers is not filtered, note that the editors should be advised that this can take lot of time
IdsLayers = layers.Select(x => x.Id).ToList().ToArray();
}
widgets = _widgetsService.GetWidgets(IdsLayers);
}
else {
widgets = _widgetsService.GetWidgets();
}
Comment on lines +89 to +103
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified logic with corrected variable naming.

Suggested change
//Only when "ContentWidgets" layer is explicitly chosen the widgets are listed, not by default (for performance reasons)
IEnumerable<WidgetPart> widgets;
var IdLayerContentWidget = layers.Where(x => x.Name.ToLowerInvariant() == "contentwidgets").Select(x => x.Id).FirstOrDefault();
if (IdLayerContentWidget > 0) {
//Ok the layer exists
var IdsLayers = layers.Where(x => x.Name.ToLowerInvariant() != "contentwidgets").Select(x => x.Id).ToList().ToArray();
if (layerId != null && (int)layerId == IdLayerContentWidget) {
//If ContentWidgets is chosen explicitly then IdsLayers is not filtered, note that the editors should be advised that this can take lot of time
IdsLayers = layers.Select(x => x.Id).ToList().ToArray();
}
widgets = _widgetsService.GetWidgets(IdsLayers);
}
else {
widgets = _widgetsService.GetWidgets();
}
// Only listing the widgets of the "ContentWidgets" layer when it's explicitly chosen, not by default (for
// performance reasons).
IEnumerable<WidgetPart> widgets;
var contentWidgetsLayer = layers.Where(x => x.Name.ToLowerInvariant() == "contentwidgets").FirstOrDefault();
if (contentWidgetsLayer == null) {
widgets = _widgetsService.GetWidgets();
}
else { // The "ContentWidgets" layer exists.
var layerIds = layers.Select(x => x.Id).ToList();
// There's no layer selected or it's not "ContentWidgets", so excluding it from the widget listing.
if (!layerId.Equals(contentWidgetsLayer.Id)) {
layerIds.Remove(contentWidgetsLayer.Id);
}
widgets = _widgetsService.GetWidgets(layerIds.ToArray());
}


if (!String.IsNullOrWhiteSpace(culture)) {
widgets = widgets.Where(x => {
if (x.Has<ILocalizableAspect>()) {
return String.Equals(x.As<ILocalizableAspect>().Culture, culture, StringComparison.InvariantCultureIgnoreCase);
}

return false;
}).ToList();
}
Expand Down