Split LeafOutputFile content into different table for performance
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
@@ -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 =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user