From 739f9f96de3194e88e6ce1c5c4c5d3d890affba3 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Tue, 16 Nov 2021 19:38:02 +0330 Subject: [PATCH] #241 adding PoetId to GanjoorCachedRelatedPoem and changing index on the table --- RMuseum/DbContext/RMuseumDbContext.cs | 2 +- ...> 20211116160621_GanjoorCachedRelatedPoems.Designer.cs} | 7 +++++-- ...oems.cs => 20211116160621_GanjoorCachedRelatedPoems.cs} | 5 +++-- RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs | 5 ++++- RMuseum/Models/Ganjoor/GanjoorCachedRelatedPoem.cs | 5 +++++ RMuseum/RMuseum.xml | 5 +++++ .../GanjoorService-Partials/GanjoorService-RelatedPoems.cs | 1 + 7 files changed, 24 insertions(+), 6 deletions(-) rename RMuseum/Migrations/{20211114151203_GanjoorCachedRelatedPoems.Designer.cs => 20211116160621_GanjoorCachedRelatedPoems.Designer.cs} (99%) rename RMuseum/Migrations/{20211114151203_GanjoorCachedRelatedPoems.cs => 20211116160621_GanjoorCachedRelatedPoems.cs} (92%) diff --git a/RMuseum/DbContext/RMuseumDbContext.cs b/RMuseum/DbContext/RMuseumDbContext.cs index d27fe7e1..2faf56e4 100644 --- a/RMuseum/DbContext/RMuseumDbContext.cs +++ b/RMuseum/DbContext/RMuseumDbContext.cs @@ -137,7 +137,7 @@ namespace RMuseum.DbContext .HasIndex(v => new { v.PoemId, v.CoupletIndex }); builder.Entity() - .HasIndex(c => new { c.PoemId, c.RelationOrder }); + .HasIndex(c => new { c.PoemId }); //Index set suggested by SQL Server Tuning Wizard -- end diff --git a/RMuseum/Migrations/20211114151203_GanjoorCachedRelatedPoems.Designer.cs b/RMuseum/Migrations/20211116160621_GanjoorCachedRelatedPoems.Designer.cs similarity index 99% rename from RMuseum/Migrations/20211114151203_GanjoorCachedRelatedPoems.Designer.cs rename to RMuseum/Migrations/20211116160621_GanjoorCachedRelatedPoems.Designer.cs index e1a5ec20..6507ace4 100644 --- a/RMuseum/Migrations/20211114151203_GanjoorCachedRelatedPoems.Designer.cs +++ b/RMuseum/Migrations/20211116160621_GanjoorCachedRelatedPoems.Designer.cs @@ -10,7 +10,7 @@ using RMuseum.DbContext; namespace RMuseum.Migrations { [DbContext(typeof(RMuseumDbContext))] - [Migration("20211114151203_GanjoorCachedRelatedPoems")] + [Migration("20211116160621_GanjoorCachedRelatedPoems")] partial class GanjoorCachedRelatedPoems { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -452,6 +452,9 @@ namespace RMuseum.Migrations b.Property("PoemId") .HasColumnType("int"); + b.Property("PoetId") + .HasColumnType("int"); + b.Property("PoetImageUrl") .HasColumnType("nvarchar(max)"); @@ -466,7 +469,7 @@ namespace RMuseum.Migrations b.HasKey("Id"); - b.HasIndex("PoemId", "RelationOrder"); + b.HasIndex("PoemId"); b.ToTable("GanjoorCachedRelatedPoems"); }); diff --git a/RMuseum/Migrations/20211114151203_GanjoorCachedRelatedPoems.cs b/RMuseum/Migrations/20211116160621_GanjoorCachedRelatedPoems.cs similarity index 92% rename from RMuseum/Migrations/20211114151203_GanjoorCachedRelatedPoems.cs rename to RMuseum/Migrations/20211116160621_GanjoorCachedRelatedPoems.cs index 48191f56..f51557a7 100644 --- a/RMuseum/Migrations/20211114151203_GanjoorCachedRelatedPoems.cs +++ b/RMuseum/Migrations/20211116160621_GanjoorCachedRelatedPoems.cs @@ -13,6 +13,7 @@ namespace RMuseum.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), PoemId = table.Column(type: "int", nullable: false), + PoetId = table.Column(type: "int", nullable: false), RelationOrder = table.Column(type: "int", nullable: false), PoetName = table.Column(type: "nvarchar(max)", nullable: true), PoetImageUrl = table.Column(type: "nvarchar(max)", nullable: true), @@ -33,9 +34,9 @@ namespace RMuseum.Migrations }); migrationBuilder.CreateIndex( - name: "IX_GanjoorCachedRelatedPoems_PoemId_RelationOrder", + name: "IX_GanjoorCachedRelatedPoems_PoemId", table: "GanjoorCachedRelatedPoems", - columns: new[] { "PoemId", "RelationOrder" }); + column: "PoemId"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs b/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs index 9bc47035..28f0e09f 100644 --- a/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs +++ b/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs @@ -450,6 +450,9 @@ namespace RMuseum.Migrations b.Property("PoemId") .HasColumnType("int"); + b.Property("PoetId") + .HasColumnType("int"); + b.Property("PoetImageUrl") .HasColumnType("nvarchar(max)"); @@ -464,7 +467,7 @@ namespace RMuseum.Migrations b.HasKey("Id"); - b.HasIndex("PoemId", "RelationOrder"); + b.HasIndex("PoemId"); b.ToTable("GanjoorCachedRelatedPoems"); }); diff --git a/RMuseum/Models/Ganjoor/GanjoorCachedRelatedPoem.cs b/RMuseum/Models/Ganjoor/GanjoorCachedRelatedPoem.cs index 7c20fbf1..77096230 100644 --- a/RMuseum/Models/Ganjoor/GanjoorCachedRelatedPoem.cs +++ b/RMuseum/Models/Ganjoor/GanjoorCachedRelatedPoem.cs @@ -12,6 +12,11 @@ /// public int PoemId { get; set; } + /// + /// poet id + /// + public int PoetId { get; set; } + /// /// poem /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index d172b2e2..8621f221 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -4626,6 +4626,11 @@ poem id + + + poet id + + poem diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedPoems.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedPoems.cs index 6803dde5..71ffdd9d 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedPoems.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedPoems.cs @@ -76,6 +76,7 @@ namespace RMuseum.Services.Implementation GanjoorCachedRelatedPoem newRelatedPoem = new GanjoorCachedRelatedPoem() { PoemId = poemId, + PoetId = relatedPoem.Cat.PoetId, RelationOrder = r, PoetName = relatedPoem.Cat.Poet.Nickname, PoetImageUrl = $"/api/ganjoor/poet/image{(await context.GanjoorCategories.Where(c => c.ParentId == null && c.PoetId == relatedPoem.Cat.PoetId).AsNoTracking().SingleAsync()).FullUrl}.gif",