Merge pull request #57 from sbwalker/master

Improve HtmlText module performance
This commit is contained in:
Shaun Walker 2019-08-16 09:51:06 -04:00 committed by GitHub
commit ed83b684ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 128 additions and 38 deletions

View File

@ -28,16 +28,14 @@
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } } public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } }
public override string Title { get { return "Edit Html/Text"; } } public override string Title { get { return "Edit Html/Text"; } }
HtmlTextInfo htmltext;
string content; string content;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper); HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
List<HtmlTextInfo> htmltextlist = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId); HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltextlist != null) if (htmltext != null)
{ {
htmltext = htmltextlist.FirstOrDefault();
content = htmltext.Content; content = htmltext.Content;
} }
} }
@ -45,6 +43,7 @@
private async Task SaveContent() private async Task SaveContent()
{ {
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper); HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null) if (htmltext != null)
{ {
htmltext.Content = content; htmltext.Content = content;

View File

@ -19,10 +19,10 @@
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper); HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
List<HtmlTextInfo> htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId); HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null) if (htmltext != null)
{ {
content = htmltext.FirstOrDefault().Content; content = htmltext.Content;
} }
} }
} }

View File

@ -27,13 +27,9 @@ namespace Oqtane.Client.Modules.HtmlText.Services
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "HtmlText"); } get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "HtmlText"); }
} }
public async Task<List<HtmlTextInfo>> GetHtmlTextAsync(int ModuleId) public async Task<HtmlTextInfo> GetHtmlTextAsync(int ModuleId)
{ {
List<HtmlTextInfo> htmltext = await http.GetJsonAsync<List<HtmlTextInfo>>(apiurl); return await http.GetJsonAsync<HtmlTextInfo>(apiurl + "/" + ModuleId.ToString());
htmltext = htmltext
.Where(item => item.ModuleId == ModuleId)
.ToList();
return htmltext;
} }
public async Task AddHtmlTextAsync(HtmlTextInfo htmltext) public async Task AddHtmlTextAsync(HtmlTextInfo htmltext)

View File

@ -6,7 +6,7 @@ namespace Oqtane.Client.Modules.HtmlText.Services
{ {
public interface IHtmlTextService public interface IHtmlTextService
{ {
Task<List<HtmlTextInfo>> GetHtmlTextAsync(int ModuleId); Task<HtmlTextInfo> GetHtmlTextAsync(int ModuleId);
Task AddHtmlTextAsync(HtmlTextInfo htmltext); Task AddHtmlTextAsync(HtmlTextInfo htmltext);

View File

@ -6,6 +6,22 @@ namespace Oqtane.Services
{ {
public interface ISettingService public interface ISettingService
{ {
Task<List<Setting>> GetHostSettingsAsync();
Task<Setting> UpdateHostSettingsAsync(List<Setting> HostSettings, string SettingName, string SettingValue);
Task<List<Setting>> GetSiteSettingsAsync(int SiteId);
Task<Setting> UpdateSiteSettingsAsync(List<Setting> SiteSettings, int SiteId, string SettingName, string SettingValue);
Task<List<Setting>> GetPageSettingsAsync(int PageId);
Task<Setting> UpdatePageSettingsAsync(List<Setting> PageSettings, int PageId, string SettingName, string SettingValue);
Task<List<Setting>> GetPageModuleSettingsAsync(int PageModuleId);
Task<Setting> UpdatePageModuleSettingsAsync(List<Setting> PageModuleSettings, int PageModuleId, string SettingName, string SettingValue);
Task<List<Setting>> GetModuleSettingsAsync(int ModuleId); Task<List<Setting>> GetModuleSettingsAsync(int ModuleId);
Task<Setting> UpdateModuleSettingsAsync(List<Setting> ModuleSettings, int ModuleId, string SettingName, string SettingValue); Task<Setting> UpdateModuleSettingsAsync(List<Setting> ModuleSettings, int ModuleId, string SettingName, string SettingValue);

View File

@ -5,7 +5,6 @@ using System.Linq;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using System.Collections.Generic; using System.Collections.Generic;
using Oqtane.Shared; using Oqtane.Shared;
using System;
namespace Oqtane.Services namespace Oqtane.Services
{ {
@ -27,6 +26,106 @@ namespace Oqtane.Services
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Setting"); } get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Setting"); }
} }
public async Task<List<Setting>> GetHostSettingsAsync()
{
return await GetSettingsAsync("Host", -1);
}
public async Task<Setting> UpdateHostSettingsAsync(List<Setting> HostSettings, string SettingName, string SettingValue)
{
Setting setting = HostSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
if (setting == null)
{
setting = new Setting();
setting.EntityName = "Host";
setting.EntityId = -1;
setting.SettingName = SettingName;
setting.SettingValue = SettingValue;
setting = await AddSettingAsync(setting);
}
else
{
setting.SettingValue = SettingValue;
setting = await UpdateSettingAsync(setting);
}
return setting;
}
public async Task<List<Setting>> GetSiteSettingsAsync(int SiteId)
{
return await GetSettingsAsync("Site", SiteId);
}
public async Task<Setting> UpdateSiteSettingsAsync(List<Setting> SiteSettings, int SiteId, string SettingName, string SettingValue)
{
Setting setting = SiteSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
if (setting == null)
{
setting = new Setting();
setting.EntityName = "Site";
setting.EntityId = SiteId;
setting.SettingName = SettingName;
setting.SettingValue = SettingValue;
setting = await AddSettingAsync(setting);
}
else
{
setting.SettingValue = SettingValue;
setting = await UpdateSettingAsync(setting);
}
return setting;
}
public async Task<List<Setting>> GetPageSettingsAsync(int PageId)
{
return await GetSettingsAsync("Page", PageId);
}
public async Task<Setting> UpdatePageSettingsAsync(List<Setting> PageSettings, int PageId, string SettingName, string SettingValue)
{
Setting setting = PageSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
if (setting == null)
{
setting = new Setting();
setting.EntityName = "Page";
setting.EntityId = PageId;
setting.SettingName = SettingName;
setting.SettingValue = SettingValue;
setting = await AddSettingAsync(setting);
}
else
{
setting.SettingValue = SettingValue;
setting = await UpdateSettingAsync(setting);
}
return setting;
}
public async Task<List<Setting>> GetPageModuleSettingsAsync(int PageModuleId)
{
return await GetSettingsAsync("PageModule", PageModuleId);
}
public async Task<Setting> UpdatePageModuleSettingsAsync(List<Setting> PageModuleSettings, int PageModuleId, string SettingName, string SettingValue)
{
Setting setting = PageModuleSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
if (setting == null)
{
setting = new Setting();
setting.EntityName = "PageModule";
setting.EntityId = PageModuleId;
setting.SettingName = SettingName;
setting.SettingValue = SettingValue;
setting = await AddSettingAsync(setting);
}
else
{
setting.SettingValue = SettingValue;
setting = await UpdateSettingAsync(setting);
}
return setting;
}
public async Task<List<Setting>> GetModuleSettingsAsync(int ModuleId) public async Task<List<Setting>> GetModuleSettingsAsync(int ModuleId)
{ {
return await GetSettingsAsync("Module", ModuleId); return await GetSettingsAsync("Module", ModuleId);

View File

@ -15,13 +15,6 @@ namespace Oqtane.Server.Modules.HtmlText.Controllers
htmltext = HtmlText; htmltext = HtmlText;
} }
// GET: api/<controller>
[HttpGet]
public IEnumerable<HtmlTextInfo> Get()
{
return htmltext.GetHtmlText();
}
// GET api/<controller>/5 // GET api/<controller>/5
[HttpGet("{id}")] [HttpGet("{id}")]
public HtmlTextInfo Get(int id) public HtmlTextInfo Get(int id)

View File

@ -15,11 +15,11 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
db = context; db = context;
} }
public IEnumerable<HtmlTextInfo> GetHtmlText() public HtmlTextInfo GetHtmlText(int ModuleId)
{ {
try try
{ {
return db.HtmlText.ToList(); return db.HtmlText.Where(item => item.ModuleId == ModuleId).FirstOrDefault();
} }
catch catch
{ {
@ -27,6 +27,7 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
} }
} }
public HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText) public HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText)
{ {
try try
@ -55,19 +56,6 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
} }
} }
public HtmlTextInfo GetHtmlText(int HtmlTextId)
{
try
{
HtmlTextInfo HtmlText = db.HtmlText.Find(HtmlTextId);
return HtmlText;
}
catch
{
throw;
}
}
public void DeleteHtmlText(int HtmlTextId) public void DeleteHtmlText(int HtmlTextId)
{ {
try try

View File

@ -5,10 +5,9 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
{ {
public interface IHtmlTextRepository public interface IHtmlTextRepository
{ {
IEnumerable<HtmlTextInfo> GetHtmlText(); HtmlTextInfo GetHtmlText(int ModuleId);
HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText); HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText);
HtmlTextInfo UpdateHtmlText(HtmlTextInfo HtmlText); HtmlTextInfo UpdateHtmlText(HtmlTextInfo HtmlText);
HtmlTextInfo GetHtmlText(int HtmlTextIdId);
void DeleteHtmlText(int HtmlTextId); void DeleteHtmlText(int HtmlTextId);
} }
} }