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