Split LeafOutputFile content into different table for performance

This commit is contained in:
2016-05-23 15:23:36 -04:00
parent 790e2494e3
commit 55f7b68bf8
21 changed files with 307 additions and 19 deletions
+8
View File
@@ -85,6 +85,7 @@
<Compile Include="Entities\LeafGasComparison.cs" />
<Compile Include="Entities\LeafInputStatusType.cs" />
<Compile Include="Entities\LeafOutputFile.cs" />
<Compile Include="Entities\LeafOutputFileContents.cs" />
<Compile Include="Entities\LeafOutputFileType.cs" />
<Compile Include="Entities\PhotosynthesisType.cs" />
<Compile Include="Migrations\201604151603282_InitialCreate.cs" />
@@ -103,6 +104,10 @@
<Compile Include="Migrations\201605191138068_LeafInputData.Designer.cs">
<DependentUpon>201605191138068_LeafInputData.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201605210257006_LeafOutputFileContents.cs" />
<Compile Include="Migrations\201605210257006_LeafOutputFileContents.Designer.cs">
<DependentUpon>201605210257006_LeafOutputFileContents.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Parsers\LeafGasComparisonParser.cs" />
<Compile Include="Remote\IPiscalClient.cs" />
@@ -159,6 +164,9 @@
<EmbeddedResource Include="Migrations\201605191138068_LeafInputData.resx">
<DependentUpon>201605191138068_LeafInputData.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201605210257006_LeafOutputFileContents.resx">
<DependentUpon>201605210257006_LeafOutputFileContents.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+6
View File
@@ -62,7 +62,13 @@ namespace LeafWeb.Core.DAL
public void DeleteLeafInput(LeafInput leafInput)
{
RemoveCollectionFromDbSet(leafInput.InputFiles, _db.LeafInputFiles);
if (leafInput.OutputFiles != null)
foreach (var outputFile in leafInput.OutputFiles.ToArray())
if (outputFile.FileContents != null)
_db.LeafOutputFileContents.Remove(outputFile.FileContents);
RemoveCollectionFromDbSet(leafInput.OutputFiles, _db.LeafOutputFiles);
RemoveCollectionFromDbSet(leafInput.StatusHistory, _db.LeafInputStatus);
// Data
if (leafInput.LeafInputData != null)
+1
View File
@@ -14,6 +14,7 @@ namespace LeafWeb.Core.DAL
public DbSet<FluxnetSite> FluxnetSites { get; set; }
public DbSet<PhotosynthesisType> PhotosynthesisTypes { get; set; }
public DbSet<LeafOutputFile> LeafOutputFiles { get; set; }
public DbSet<LeafOutputFileContents> LeafOutputFileContents { get; set; }
public DbSet<LeafInputData> LeafInputData { get; set; }
public DbSet<LeafInputDataCurve> LeafInputDataCurves { get; set; }
public DbSet<LeafInputDataPhotosynthetic> LeafInputDataPhotosynthetic { get; set; }
+2 -2
View File
@@ -63,7 +63,7 @@ namespace LeafWeb.Core.Entities
foreach (var outputFile in OutputFiles.Where(f => !fileType.HasValue || f.FileType==fileType.Value))
{
var entry = archive.CreateEntry(outputFile.Filename);
using (var originalFileStream = new MemoryStream(outputFile.Contents))
using (var originalFileStream = new MemoryStream(outputFile.FileContents.Contents))
using (var entryStream = entry.Open())
originalFileStream.CopyTo(entryStream);
}
@@ -73,7 +73,7 @@ namespace LeafWeb.Core.Entities
public int GetOutputFileSizeSum()
{
return OutputFiles.Sum(o => o.Contents.Length);
return OutputFiles.Sum(o => o.FileContents.Contents.Length);
}
}
}
+1 -6
View File
@@ -7,12 +7,7 @@ namespace LeafWeb.Core.Entities
public int Id { get; set; }
public virtual LeafInput LeafInput { get; set; }
/// <summary>
/// Parsed values from the LeafInput used in LeafWeb for filtering/searching
/// </summary>
// public virtual LeafInputInfo LeafInputInfo { get; set; }
public string Filename { get; set; }
public byte[] Contents { get; set; }
+1 -1
View File
@@ -24,7 +24,7 @@ namespace LeafWeb.Core.Entities
public string Filename { get; set; }
public byte[] Contents { get; set; }
public virtual LeafOutputFileContents FileContents { get; set; }
public bool IsLeafChartFile => Filename?.Contains(Filename_LeafChart) ?? false;
public bool IsErrorMessage => Filename?.Contains(Filename_ErrorMessage) ?? false;
+14
View File
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace LeafWeb.Core.Entities
{
public class LeafOutputFileContents
{
[ForeignKey("LeafOutputFile")]
public int Id { get; set; }
public virtual LeafOutputFile LeafOutputFile { get; set; }
public byte[] Contents { get; set; }
}
}
@@ -0,0 +1,29 @@
// <auto-generated />
namespace LeafWeb.Core.Migrations
{
using System.CodeDom.Compiler;
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Infrastructure;
using System.Resources;
[GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")]
public sealed partial class LeafOutputFileContents : IMigrationMetadata
{
private readonly ResourceManager Resources = new ResourceManager(typeof(LeafOutputFileContents));
string IMigrationMetadata.Id
{
get { return "201605210257006_LeafOutputFileContents"; }
}
string IMigrationMetadata.Source
{
get { return null; }
}
string IMigrationMetadata.Target
{
get { return Resources.GetString("Target"); }
}
}
}
@@ -0,0 +1,45 @@
namespace LeafWeb.Core.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class LeafOutputFileContents : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.LeafOutputFileContents",
c => new
{
Id = c.Int(nullable: false),
Contents = c.Binary(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.LeafOutputFile", t => t.Id)
.Index(t => t.Id);
Sql(
"INSERT INTO dbo.LeafOutputFileContents "
+ "(Id, Contents) "
+ "SELECT Id, Contents "
+ "FROM dbo.LeafOutputFile");
DropColumn("dbo.LeafOutputFile", "Contents");
}
public override void Down()
{
AddColumn("dbo.LeafOutputFile", "Contents", c => c.Binary());
Sql(
"UPDATE dbo.LeafOutputFile "
+ "SET dbo.LeafOutputFile.Contents = FileContents.Contents "
+ "FROM dbo.LeafOutputFileContents as FileContents "
+ "WHERE dbo.LeafOutputFile.Id = FileContents.Id");
DropForeignKey("dbo.LeafOutputFileContents", "Id", "dbo.LeafOutputFile");
DropIndex("dbo.LeafOutputFileContents", new[] { "Id" });
DropTable("dbo.LeafOutputFileContents");
}
}
}
File diff suppressed because one or more lines are too long
+2
View File
@@ -21,6 +21,8 @@ namespace LeafWeb.Core.Remote
new MapperConfiguration(cfg =>
{
cfg.CreateMap<PiscalLeafOutputFile, LeafOutputFile>()
.ForMember(dest => dest.FileContents, opt =>
opt.ResolveUsing(src => new LeafOutputFileContents {Contents = src.Contents}))
.ForMember(dest => dest.FileType, opt =>
opt.ResolveUsing(src =>
{
+2 -2
View File
@@ -28,7 +28,7 @@ namespace LeafWeb.Web.Controllers
try
{
var curveIds = GetCurveIds(leafOutputFile.Contents);
var curveIds = GetCurveIds(leafOutputFile.FileContents.Contents);
var viewModel = new ChartViewModel
{
@@ -54,7 +54,7 @@ namespace LeafWeb.Web.Controllers
if (leafOutputFile == null)
throw new ArgumentOutOfRangeException(); // TODO: break
var curveData = GetCurveData(leafOutputFile.Contents, curveId);
var curveData = GetCurveData(leafOutputFile.FileContents.Contents, curveId);
if (curveData == null)
return File("/Content/favicon/apple-icon-57x57.png", "image/png"); // TODO: different image ?
+38 -1
View File
@@ -1,8 +1,9 @@
using System;
using System.Linq;
using System.Web.Mvc;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Utility;
using LeafWeb.Web.Attributes;
using LeafWeb.Web.ViewModels.LeafInput;
using LeafWeb.Web.ViewModels.Results;
using LeafWeb.Web.ViewModels.ResultsAdmin;
@@ -20,6 +21,42 @@ namespace LeafWeb.Web.Controllers
return View(viewModel);
}
public ActionResult Details(int id)
{
var leafInput = DataService.GetLeafInput(id);
var viewModel = new LeafInputViewModel(leafInput);
return View(viewModel);
}
public ActionResult DownloadOutputToUser(int id)
{
return GetOutputZip(id, LeafOutputFileType.ToUser);
}
public ActionResult DownloadOutputNotToUser(int id)
{
return GetOutputZip(id, LeafOutputFileType.NotToUser);
}
public ActionResult DownloadOutputCleanedInput(int id)
{
return GetOutputZip(id, LeafOutputFileType.CleanedInput);
}
private ActionResult GetOutputZip(int id, LeafOutputFileType type)
{
var leafInput = DataService.GetLeafInput(id);
if (leafInput == null)
return View("DownloadNotFound");
var zip = leafInput.GetOutputFileZip(type);
var filename = $"{leafInput.Identifier.FilterValidFilename()}_{type}.zip";
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
}
public ActionResult Delete(int id)
{
var leafInput = DataService.GetLeafInput(id);
+3 -3
View File
@@ -61,7 +61,7 @@ namespace LeafWeb.Web.Services
var outputErrorMessage = leafInput.OutputErrorMessage;
if (outputErrorMessage != null)
SendLeafWebError(leafInput, outputErrorMessage.Contents.GetString());
SendLeafWebError(leafInput, outputErrorMessage.FileContents.Contents.GetString());
else
SendLeafWebSuccess(leafInput);
}
@@ -99,7 +99,7 @@ namespace LeafWeb.Web.Services
var fileStreams =
(from outputFile in
leafInput.OutputFiles
select Tuple.Create(outputFile, new MemoryStream(outputFile.Contents))).ToList();
select Tuple.Create(outputFile, new MemoryStream(outputFile.FileContents.Contents))).ToList();
try
{
foreach (var fileStream in fileStreams)
@@ -151,7 +151,7 @@ namespace LeafWeb.Web.Services
return Environment.NewLine + Environment.NewLine
+ "The following warning message was generated."
+ Environment.NewLine + Environment.NewLine
+ leafInput.OutputWarningMessage.Contents.GetString()
+ leafInput.OutputWarningMessage.FileContents.Contents.GetString()
+ Environment.NewLine;
return string.Empty;
}
+1 -1
View File
@@ -47,7 +47,7 @@ namespace LeafWeb.Web.Services.PiscalQueue
{
try
{
var parser = new LeafInputCsvParser(outputFile.Contents);
var parser = new LeafInputCsvParser(outputFile.FileContents.Contents);
var data = parser.Parse();
data.LeafInput = leafInput;
data.LeafOutputFile = outputFile;
+1 -1
View File
@@ -16,7 +16,7 @@
{
<div class="form-actions">
<input type="submit" value="Delete" class="btn btn-warning" />
@Html.ActionLink("Cancel", "Details", new { id = Model.LeafInputId }, new { @class = "btn" })
@Html.ActionLink("Cancel", "Index", new { id = Model.LeafInputId }, new { @class = "btn" })
</div>
}
</div>
+13
View File
@@ -0,0 +1,13 @@
@model LeafWeb.Web.ViewModels.ResultsAdmin.LeafInputViewModel
@{
ViewBag.Title = "Details";
}
<h1>@ViewBag.Title</h1>
<div class="center-content well">
@Html.DisplayForModel()
</div>
@@ -0,0 +1,10 @@
@{
ViewBag.Title = "Not Found";
}
<h1>
@ViewBag.Title
</h1>
<p>The given download link was not found.</p>
<code>@Html.Raw(Request.Url)</code>
+1 -1
View File
@@ -19,8 +19,8 @@
: Html.Raw("")),
grid.Column("Total Results: " + Model.Count(), format:
@<div class="btn-group" role="group">
@Html.ActionLink("Edit", "Edit", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
@Html.ActionLink("Details", "Details", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
@Html.ActionLink("Download", "DownloadOutputToUser", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
@Html.ActionLink("Delete", "Delete", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role="button" })
</div>)
),
+1 -1
View File
@@ -36,7 +36,7 @@
</appSettings>
<system.web>
<compilation targetFramework="4.5" debug="true" />
<customErrors mode="Off"/>
<!-- max 1GB --><httpRuntime targetFramework="4.5" executionTimeout="3600" maxRequestLength="1000000000" />
<globalization culture="en-US" uiCulture="en-US" enableClientBasedCulture="false" requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
+2
View File
@@ -703,6 +703,8 @@
<Content Include="Views\Chart\DataError.cshtml" />
<Content Include="Views\ResultsAdmin\Index.cshtml" />
<Content Include="Views\ResultsAdmin\Delete.cshtml" />
<Content Include="Views\ResultsAdmin\DownloadNotFound.cshtml" />
<Content Include="Views\ResultsAdmin\Details.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>