optimize assembly loading performance
This commit is contained in:
parent
e92d34a9e3
commit
a152d8664d
|
@ -106,43 +106,22 @@ namespace Oqtane.Controllers
|
||||||
// GET api/<controller>/list
|
// GET api/<controller>/list
|
||||||
[HttpGet("list")]
|
[HttpGet("list")]
|
||||||
public List<string> List()
|
public List<string> List()
|
||||||
{
|
|
||||||
var alias = _tenantManager.GetAlias();
|
|
||||||
var site = _sites.GetSite(alias.SiteId);
|
|
||||||
if (site != null && site.Runtime == "WebAssembly")
|
|
||||||
{
|
{
|
||||||
return GetAssemblyList().Select(item => item.HashedName).ToList();
|
return GetAssemblyList().Select(item => item.HashedName).ToList();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return new List<string>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET api/<controller>/load?list=x,y
|
|
||||||
[HttpGet("load")]
|
|
||||||
public IActionResult Load(string list = "*")
|
|
||||||
{
|
|
||||||
var alias = _tenantManager.GetAlias();
|
|
||||||
var site = _sites.GetSite(alias.SiteId);
|
|
||||||
if (site != null && site.Runtime == "WebAssembly")
|
|
||||||
{
|
|
||||||
return File(GetAssemblies(list), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return File(GetEmptyZip(), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ClientAssembly> GetAssemblyList()
|
private List<ClientAssembly> GetAssemblyList()
|
||||||
{
|
{
|
||||||
var siteKey = _tenantManager.GetAlias().SiteKey;
|
var alias = _tenantManager.GetAlias();
|
||||||
|
|
||||||
return _cache.GetOrCreate($"assemblieslist:{siteKey}", entry =>
|
return _cache.GetOrCreate($"assemblieslist:{alias.SiteKey}", entry =>
|
||||||
|
{
|
||||||
|
var assemblyList = new List<ClientAssembly>();
|
||||||
|
|
||||||
|
var site = _sites.GetSite(alias.SiteId);
|
||||||
|
if (site != null && site.Runtime == "WebAssembly")
|
||||||
{
|
{
|
||||||
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
var assemblyList = new List<ClientAssembly>();
|
|
||||||
|
|
||||||
// testmode setting is used for validating that the API is downloading the appropriate assemblies to the client
|
// testmode setting is used for validating that the API is downloading the appropriate assemblies to the client
|
||||||
bool hashfilename = true;
|
bool hashfilename = true;
|
||||||
|
@ -152,7 +131,7 @@ namespace Oqtane.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// get site assemblies which should be downloaded to client
|
// get site assemblies which should be downloaded to client
|
||||||
var assemblies = _serverState.GetServerState(siteKey).Assemblies;
|
var assemblies = _serverState.GetServerState(alias.SiteKey).Assemblies;
|
||||||
|
|
||||||
// populate assembly list
|
// populate assembly list
|
||||||
foreach (var assembly in assemblies)
|
foreach (var assembly in assemblies)
|
||||||
|
@ -190,29 +169,39 @@ namespace Oqtane.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return assemblyList;
|
return assemblyList;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET api/<controller>/load?list=x,y
|
||||||
|
[HttpGet("load")]
|
||||||
|
public IActionResult Load(string list = "*")
|
||||||
|
{
|
||||||
|
return File(GetAssemblies(list), System.Net.Mime.MediaTypeNames.Application.Octet, "oqtane.dll");
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] GetAssemblies(string list)
|
private byte[] GetAssemblies(string list)
|
||||||
{
|
{
|
||||||
var siteKey = _tenantManager.GetAlias().SiteKey;
|
var alias = _tenantManager.GetAlias();
|
||||||
|
|
||||||
if (list == "*")
|
if (list == "*")
|
||||||
{
|
{
|
||||||
return _cache.GetOrCreate($"assemblies:{siteKey}", entry =>
|
return _cache.GetOrCreate($"assemblies:{alias.SiteKey}", entry =>
|
||||||
{
|
{
|
||||||
return GetZIP(list);
|
return GetZIP(list, alias);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return GetZIP(list);
|
return GetZIP(list, alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] GetZIP(string list)
|
private byte[] GetZIP(string list, Alias alias)
|
||||||
|
{
|
||||||
|
var site = _sites.GetSite(alias.SiteId);
|
||||||
|
if (site != null && site.Runtime == "WebAssembly")
|
||||||
{
|
{
|
||||||
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
|
||||||
|
@ -257,16 +246,14 @@ namespace Oqtane.Controllers
|
||||||
return memoryStream.ToArray();
|
return memoryStream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
private byte[] GetEmptyZip()
|
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
// return empty zip
|
||||||
{
|
using (var memoryStream = new MemoryStream())
|
||||||
using (var zip = new ZipArchive(stream, ZipArchiveMode.Create))
|
|
||||||
{
|
{
|
||||||
|
using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create)) {}
|
||||||
|
return memoryStream.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream.ToArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user