mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Optimization widget queries
--HG-- branch : 1.x
This commit is contained in:
@@ -46,7 +46,6 @@ namespace Orchard.Widgets.Filters {
|
||||
|
||||
// Once the Rule Engine is done:
|
||||
// Get Layers and filter by zone and rule
|
||||
IEnumerable<WidgetPart> widgetParts = _widgetsService.GetWidgets();
|
||||
IEnumerable<LayerPart> activeLayers = _contentManager.Query<LayerPart, LayerPartRecord>().List();
|
||||
|
||||
var activeLayerIds = new List<int>();
|
||||
@@ -62,6 +61,8 @@ namespace Orchard.Widgets.Filters {
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerable<WidgetPart> widgetParts = _widgetsService.GetWidgets(activeLayerIds.ToArray());
|
||||
|
||||
// Build and add shape to zone.
|
||||
var zones = workContext.Layout.Zones;
|
||||
foreach (var widgetPart in widgetParts) {
|
||||
@@ -77,10 +78,8 @@ namespace Orchard.Widgets.Filters {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (activeLayerIds.Contains(commonPart.Container.ContentItem.Id)) {
|
||||
var widgetShape = _contentManager.BuildDisplay(widgetPart);
|
||||
zones[widgetPart.Record.Zone].Add(widgetShape, widgetPart.Record.Position);
|
||||
}
|
||||
var widgetShape = _contentManager.BuildDisplay(widgetPart);
|
||||
zones[widgetPart.Record.Zone].Add(widgetShape, widgetPart.Record.Position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -36,6 +36,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
|
@@ -16,6 +16,7 @@ namespace Orchard.Widgets.Services {
|
||||
IEnumerable<WidgetPart> GetWidgets();
|
||||
IEnumerable<WidgetPart> GetOrphanedWidgets();
|
||||
IEnumerable<WidgetPart> GetWidgets(int layerId);
|
||||
IEnumerable<WidgetPart> GetWidgets(int[] layerIds);
|
||||
|
||||
WidgetPart GetWidget(int widgetId);
|
||||
WidgetPart CreateWidget(int layerId, string widgetType, string title, string position, string zone);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using NHibernate.Criterion;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Environment.Extensions;
|
||||
@@ -47,24 +48,34 @@ namespace Orchard.Widgets.Services {
|
||||
.List();
|
||||
}
|
||||
|
||||
private IEnumerable<WidgetPart> GetAllWidgets() {
|
||||
public IEnumerable<WidgetPart> GetWidgets() {
|
||||
return _contentManager
|
||||
.Query<WidgetPart, WidgetPartRecord>()
|
||||
.WithQueryHints(new QueryHints().ExpandRecords<CommonPartRecord>()).
|
||||
List();
|
||||
}
|
||||
|
||||
public IEnumerable<WidgetPart> GetOrphanedWidgets() {
|
||||
return _contentManager
|
||||
.Query<WidgetPart, WidgetPartRecord>()
|
||||
.Where<CommonPartRecord>(x => x.Container == null)
|
||||
.List();
|
||||
}
|
||||
|
||||
public IEnumerable<WidgetPart> GetWidgets(int layerId) {
|
||||
return _contentManager
|
||||
.Query<WidgetPart, WidgetPartRecord>()
|
||||
.Where<CommonPartRecord>(x => x.Container.Id == layerId)
|
||||
.WithQueryHints(new QueryHints().ExpandRecords<CommonPartRecord>())
|
||||
.List();
|
||||
}
|
||||
|
||||
public IEnumerable<WidgetPart> GetWidgets() {
|
||||
return GetAllWidgets().Where(w => w.Has<ICommonPart>());
|
||||
}
|
||||
|
||||
// info: (heskew) Just including invalid widgets for now. Eventually need to include any in a layer which no longer exists if possible.
|
||||
public IEnumerable<WidgetPart> GetOrphanedWidgets() {
|
||||
return GetAllWidgets().Where(w => !w.Has<ICommonPart>());
|
||||
}
|
||||
|
||||
public IEnumerable<WidgetPart> GetWidgets(int layerId) {
|
||||
return GetWidgets().Where(widgetPart => widgetPart.As<ICommonPart>().Container.ContentItem.Id == layerId);
|
||||
public IEnumerable<WidgetPart> GetWidgets(int[] layerIds) {
|
||||
return _contentManager
|
||||
.Query<WidgetPart, WidgetPartRecord>()
|
||||
.Where<CommonPartRecord>(x => x.Container.Id.IsIn(layerIds))
|
||||
.WithQueryHints(new QueryHints().ExpandRecords<CommonPartRecord>())
|
||||
.List();
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetZones() {
|
||||
|
Reference in New Issue
Block a user