Skip to content

Commit

Permalink
Use DbWeightsData.Format property instead of hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed Mar 12, 2024
1 parent 3a53998 commit f688177
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 90 deletions.
4 changes: 2 additions & 2 deletions SightKeeper.Data/Configuration/WeightsDataConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void Configure(EntityTypeBuilder<DbWeightsData> builder)
builder.HasFlakeIdKey();
builder.ToTable("WeightsData");
builder.ComplexProperty(weightsData => weightsData.Data, subBuilder => subBuilder.Property(weights => weights.Content).HasColumnName("Content"));
builder.HasDiscriminator<byte>("Type").HasValue<ONNXWeightsData>(0).HasValue<PTWeightsData>(1);
builder.HasIndex("Type", "WeightsId").IsUnique();
builder.Property(weightsData => weightsData.Format);
builder.HasIndex("WeightsId", "Format").IsUnique();
}
}
14 changes: 11 additions & 3 deletions SightKeeper.Data/DbWeightsData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@

namespace SightKeeper.Data;

internal abstract class DbWeightsData
internal sealed class DbWeightsData
{
public enum DataFormat
{
ONNX,
PT
}

public WeightsData Data { get; }
public Weights Weights { get; }
public DataFormat Format { get; }

protected DbWeightsData(WeightsData data, Weights weights)
public DbWeightsData(WeightsData data, Weights weights, DataFormat format)
{
Data = data;
Weights = weights;
Format = format;
}

protected DbWeightsData()
private DbWeightsData()
{
Data = null!;
Weights = null!;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
Id = table.Column<long>(type: "INTEGER", nullable: false),
WeightsId = table.Column<long>(type: "INTEGER", nullable: false),
Type = table.Column<byte>(type: "INTEGER", nullable: false),
Format = table.Column<int>(type: "INTEGER", nullable: false),
Content = table.Column<byte[]>(type: "BLOB", nullable: false)
},
constraints: table =>
Expand Down Expand Up @@ -404,16 +404,11 @@ protected override void Up(MigrationBuilder migrationBuilder)
column: "LibraryId");

migrationBuilder.CreateIndex(
name: "IX_WeightsData_Type_WeightsId",
name: "IX_WeightsData_WeightsId_Format",
table: "WeightsData",
columns: new[] { "Type", "WeightsId" },
columns: new[] { "WeightsId", "Format" },
unique: true);

migrationBuilder.CreateIndex(
name: "IX_WeightsData_WeightsId",
table: "WeightsData",
column: "WeightsId");

migrationBuilder.CreateIndex(
name: "IX_WeightsItemClasses_ItemClassId",
table: "WeightsItemClasses",
Expand Down
24 changes: 2 additions & 22 deletions SightKeeper.Data/Migrations/AppDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<long>("Id")
.HasColumnType("INTEGER");

b.Property<byte>("Type")
b.Property<int>("Format")
.HasColumnType("INTEGER");

b.Property<long>("WeightsId")
Expand All @@ -41,16 +41,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Id");

b.HasIndex("WeightsId");

b.HasIndex("Type", "WeightsId")
b.HasIndex("WeightsId", "Format")
.IsUnique();

b.ToTable("WeightsData", (string)null);

b.HasDiscriminator<byte>("Type");

b.UseTphMappingStrategy();
});

modelBuilder.Entity("SightKeeper.Domain.Model.DataSets.Asset", b =>
Expand Down Expand Up @@ -385,20 +379,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("WeightsItemClasses");
});

modelBuilder.Entity("SightKeeper.Data.ONNXWeightsData", b =>
{
b.HasBaseType("SightKeeper.Data.DbWeightsData");

b.HasDiscriminator().HasValue((byte)0);
});

modelBuilder.Entity("SightKeeper.Data.PTWeightsData", b =>
{
b.HasBaseType("SightKeeper.Data.DbWeightsData");

b.HasDiscriminator().HasValue((byte)1);
});

modelBuilder.Entity("SightKeeper.Data.DbWeightsData", b =>
{
b.HasOne("SightKeeper.Domain.Model.DataSets.Weights", "Weights")
Expand Down
14 changes: 0 additions & 14 deletions SightKeeper.Data/ONNXWeightsData.cs

This file was deleted.

14 changes: 0 additions & 14 deletions SightKeeper.Data/PTWeightsData.cs

This file was deleted.

6 changes: 2 additions & 4 deletions SightKeeper.Data/Services/DbWeightsDataAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public override WeightsData LoadWeightsPTData(Weights weights)

protected override void SaveWeightsData(Weights weights, WeightsData onnxData, WeightsData ptData)
{
ONNXWeightsData onnxWeightsData = new(onnxData, weights);
PTWeightsData ptWeightsData = new(ptData, weights);
_dbContext.Add(onnxWeightsData);
_dbContext.Add(ptWeightsData);
_dbContext.Add(new DbWeightsData(onnxData, weights, DbWeightsData.DataFormat.ONNX));
_dbContext.Add(new DbWeightsData(ptData, weights, DbWeightsData.DataFormat.PT));
}
protected override void RemoveWeightsData(Weights weights)
{
Expand Down

0 comments on commit f688177

Please sign in to comment.