Skip to content

Commit

Permalink
ekun008
Browse files Browse the repository at this point in the history
  • Loading branch information
siteserverekun committed Jun 16, 2017
1 parent 879aebf commit aa4805d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
12 changes: 10 additions & 2 deletions source/SiteServer.BackgroundPages/Cms/PageConfigurationCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class PageConfigurationCreate : BasePageCms
public PlaceHolder phIsCreateStaticContentByAddDate;
public DateTimeTextBox tbCreateStaticContentAddDate;

public RadioButtonList IsCreateMultiThread; // 是否启用多线程生成页面

public void Page_Load(object sender, EventArgs e)
{
if (IsForbidden) return;
Expand Down Expand Up @@ -78,8 +80,12 @@ public void Page_Load(object sender, EventArgs e)
{
tbCreateStaticContentAddDate.DateTime = PublishmentSystemInfo.Additional.CreateStaticContentAddDate;
}

EBooleanUtils.AddListItems(IsCreateMultiThread, "启用", "不启用");
ControlUtils.SelectListItemsIgnoreCase(IsCreateMultiThread, PublishmentSystemInfo.Additional.IsCreateMultiThread.ToString());

}
}
}

public void IsCreateStaticContentByAddDate_SelectedIndexChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -108,7 +114,9 @@ public override void Submit_OnClick(object sender, EventArgs e)
if (PublishmentSystemInfo.Additional.IsCreateStaticContentByAddDate)
{
PublishmentSystemInfo.Additional.CreateStaticContentAddDate = tbCreateStaticContentAddDate.DateTime;
}
}

PublishmentSystemInfo.Additional.IsCreateMultiThread = TranslateUtils.ToBool(IsCreateMultiThread.SelectedValue);

try
{
Expand Down
6 changes: 6 additions & 0 deletions source/SiteServer.CMS/Model/PublishmentSystemInfoExtend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ public DateTime CreateStaticContentAddDate
set { SetExtendedAttribute("CreateStaticContentAddDate", DateUtils.GetDateString(value)); }
}

public bool IsCreateMultiThread
{
get { return GetBool("IsCreateMultiThread", false); }
set { SetExtendedAttribute("IsCreateMultiThread", value.ToString()); }
}

/****************站点地图设置********************/

public string SiteMapGooglePath
Expand Down
63 changes: 43 additions & 20 deletions source/SiteServer.CMS/StlParser/FileSystemObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public void CreateChannel(int nodeId)

//for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++)
//{
// PageContentsDetail(filePath, pageInfo, stlLabelList, pageContentsElementParser, contentBuilder, stlElementTranslated, totalNum, pageCount, currentPageIndex);

// var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null);
// var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true);
// var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml));
Expand All @@ -190,16 +192,26 @@ public void CreateChannel(int nodeId)
// pageInfo.ClearLastPageScript();
//}

for (int i = 1; i <= pageCount; i = i + 3)
if (PublishmentSystemInfo.Additional.IsCreateMultiThread) // 多线程并发生成页面
{
var list = new List<int>();
list.Add(i);
if (i <= pageCount - 1)
list.Add(i + 1);
if (i <= pageCount - 2)
list.Add(i + 2);
Parallel.ForEach(list, currentPageIndex => PageContentsDetail(filePath, pageInfo, stlLabelList, pageContentsElementParser, contentBuilder, stlElementTranslated, totalNum, pageCount, currentPageIndex));
for (int i = 1; i <= pageCount; i = i + 3)
{
var list = new List<int>();
list.Add(i);
if (i <= pageCount - 1)
list.Add(i + 1);
if (i <= pageCount - 2)
list.Add(i + 2);
Parallel.ForEach(list, currentPageIndex => PageContentsDetail(filePath, pageInfo, stlLabelList, pageContentsElementParser, contentBuilder, stlElementTranslated, totalNum, pageCount, currentPageIndex));
}
}
else // 单线程生成页面
{
for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++)
{
PageContentsDetail(filePath, pageInfo, stlLabelList, pageContentsElementParser, contentBuilder, stlElementTranslated, totalNum, pageCount, currentPageIndex);
}
}

}
//如果标签中存在<stl:pageChannels>
Expand Down Expand Up @@ -316,21 +328,32 @@ public void CreateContents(int nodeId)
var tableName = NodeManager.GetTableName(PublishmentSystemInfo, nodeInfo);
var orderByString = ETaxisTypeUtils.GetContentOrderByString(ETaxisType.OrderByTaxisDesc);
var contentIdList = DataProvider.ContentDao.GetContentIdListChecked(tableName, nodeId, orderByString);

//foreach (var contentId in contentIdList)
//{
// CreateContent(tableStyle, tableName, nodeId, contentId);

// CreateContent(tableStyle, tableName, nodeId, contentId);
//}
for (int i = 0; i < contentIdList.Count; i = i + 3)
{
var list = new List<int>();
list.Add(contentIdList[i]);
if (i < contentIdList.Count - 1)
list.Add(contentIdList[i + 1]);
if (i < contentIdList.Count - 2)
list.Add(contentIdList[i + 2]);
Parallel.ForEach(list, contentId => CreateContent(tableStyle, tableName, nodeId, contentId));

if (PublishmentSystemInfo.Additional.IsCreateMultiThread) // 多线程并发生成页面
{
for (int i = 0; i < contentIdList.Count; i = i + 3)
{
var list = new List<int>();
list.Add(contentIdList[i]);
if (i < contentIdList.Count - 1)
list.Add(contentIdList[i + 1]);
if (i < contentIdList.Count - 2)
list.Add(contentIdList[i + 2]);
Parallel.ForEach(list, contentId => CreateContent(tableStyle, tableName, nodeId, contentId));
}
}
else // 单线程生成页面
{
foreach (var contentId in contentIdList)
{
CreateContent(tableStyle, tableName, nodeId, contentId);

}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
</td>
</tr>
</asp:PlaceHolder>
<tr>
<td>是否启用多线程生成页面:</td>
<td>
<asp:RadioButtonList ID="IsCreateMultiThread" RepeatDirection="Horizontal" class="noborder" runat="server"></asp:RadioButtonList>
<span>此功能通常用于CMS服务器配置较高而且现在生成页面时CPU和内存利用率不太高(不超过60%)时建议启用</span>
</td>
</tr>
</table>

<hr />
Expand Down

0 comments on commit aa4805d

Please sign in to comment.