From 40a4f7bc35cd9e06e39c8075fbba5b3817ad2822 Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:41:08 +0200 Subject: [PATCH] Minor DB schema fixes + fix pregenerator not distincting the list --- ReplayBrowser/Data/CollectedPlayerData.cs | 7 - ...oveForeignKeysJobCOuntCharData.Designer.cs | 476 ++++++++++++++++++ ...04031_RemoveForeignKeysJobCOuntCharData.cs | 22 + .../ReplayDbContextModelSnapshot.cs | 8 +- .../Services/ProfilePregeneratorService.cs | 2 + 5 files changed, 502 insertions(+), 13 deletions(-) create mode 100644 ReplayBrowser/Data/Migrations/20240712104031_RemoveForeignKeysJobCOuntCharData.Designer.cs create mode 100644 ReplayBrowser/Data/Migrations/20240712104031_RemoveForeignKeysJobCOuntCharData.cs diff --git a/ReplayBrowser/Data/CollectedPlayerData.cs b/ReplayBrowser/Data/CollectedPlayerData.cs index 21b060a..bfdcad8 100644 --- a/ReplayBrowser/Data/CollectedPlayerData.cs +++ b/ReplayBrowser/Data/CollectedPlayerData.cs @@ -63,10 +63,6 @@ public override int GetHashCode() public class CharacterData { public int Id { get; set; } - - // Foreign key - public CollectedPlayerData? CollectedPlayerData { get; set; } - public string CharacterName { get; set; } public DateTime LastPlayed { get; set; } = DateTime.MinValue; public int RoundsPlayed { get; set; } @@ -76,9 +72,6 @@ public class JobCountData { public int Id { get; set; } - // Foreign key - public CollectedPlayerData? CollectedPlayerData { get; set; } - public string JobPrototype { get; set; } public int RoundsPlayed { get; set; } public DateTime LastPlayed { get; set; } = DateTime.MinValue; diff --git a/ReplayBrowser/Data/Migrations/20240712104031_RemoveForeignKeysJobCOuntCharData.Designer.cs b/ReplayBrowser/Data/Migrations/20240712104031_RemoveForeignKeysJobCOuntCharData.Designer.cs new file mode 100644 index 0000000..5370a5d --- /dev/null +++ b/ReplayBrowser/Data/Migrations/20240712104031_RemoveForeignKeysJobCOuntCharData.Designer.cs @@ -0,0 +1,476 @@ +// +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using NpgsqlTypes; +using ReplayBrowser.Data; + +#nullable disable + +namespace Server.Migrations +{ + [DbContext(typeof(ReplayDbContext))] + [Migration("20240712104031_RemoveForeignKeysJobCOuntCharData")] + partial class RemoveForeignKeysJobCOuntCharData + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ReplayBrowser.Data.CharacterData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CharacterName") + .IsRequired() + .HasColumnType("text"); + + b.Property("CollectedPlayerDataPlayerGuid") + .HasColumnType("uuid"); + + b.Property("LastPlayed") + .HasColumnType("timestamp with time zone"); + + b.Property("RoundsPlayed") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CollectedPlayerDataPlayerGuid"); + + b.ToTable("CharacterData"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.CollectedPlayerData", b => + { + b.Property("PlayerGuid") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("GeneratedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsWatched") + .HasColumnType("boolean"); + + b.Property("LastSeen") + .HasColumnType("timestamp with time zone"); + + b.Property("PlayerDataId") + .HasColumnType("integer"); + + b.Property("TotalAntagRoundsPlayed") + .HasColumnType("integer"); + + b.Property("TotalEstimatedPlaytime") + .HasColumnType("interval"); + + b.Property("TotalRoundsPlayed") + .HasColumnType("integer"); + + b.HasKey("PlayerGuid"); + + b.HasIndex("PlayerDataId"); + + b.HasIndex("PlayerGuid") + .IsUnique(); + + b.ToTable("PlayerProfiles", (string)null); + }); + + modelBuilder.Entity("ReplayBrowser.Data.JobCountData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CollectedPlayerDataPlayerGuid") + .HasColumnType("uuid"); + + b.Property("JobPrototype") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastPlayed") + .HasColumnType("timestamp with time zone"); + + b.Property("RoundsPlayed") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CollectedPlayerDataPlayerGuid"); + + b.ToTable("JobCountData"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Account.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property>("FavoriteReplays") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("Guid") + .HasColumnType("uuid"); + + b.Property("IsAdmin") + .HasColumnType("boolean"); + + b.Property>("SavedProfiles") + .IsRequired() + .HasColumnType("uuid[]"); + + b.Property("SettingsId") + .HasColumnType("integer"); + + b.Property("Username") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("Guid") + .IsUnique(); + + b.HasIndex("SettingsId"); + + b.HasIndex("Username"); + + b.ToTable("Accounts", (string)null); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Account.AccountSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property>("Friends") + .IsRequired() + .HasColumnType("uuid[]"); + + b.Property("RedactInformation") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.ToTable("AccountSettings"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Account.HistoryEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AccountId") + .HasColumnType("integer"); + + b.Property("Action") + .IsRequired() + .HasColumnType("text"); + + b.Property("Details") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.ToTable("HistoryEntry"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.GdprRequest", b => + { + b.Property("Guid") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.HasKey("Guid"); + + b.ToTable("GdprRequests", (string)null); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Notice", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EndDate") + .HasColumnType("timestamp with time zone"); + + b.Property("Message") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Notices", (string)null); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.ParsedReplay", b => + { + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Name"); + + b.ToTable("ParsedReplays", (string)null); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Antag") + .HasColumnType("boolean"); + + b.Property>("AntagPrototypes") + .IsRequired() + .HasColumnType("text[]"); + + b.Property>("JobPrototypes") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("PlayerGuid") + .HasColumnType("uuid"); + + b.Property("PlayerIcName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PlayerOocName") + .IsRequired() + .HasColumnType("text"); + + b.Property("ReplayId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("PlayerGuid"); + + b.HasIndex("PlayerIcName"); + + b.HasIndex("PlayerOocName"); + + b.HasIndex("ReplayId"); + + b.ToTable("Players", (string)null); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Replay", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Duration") + .IsRequired() + .HasColumnType("text"); + + b.Property("EndTick") + .HasColumnType("integer"); + + b.Property("EndTime") + .IsRequired() + .HasColumnType("text"); + + b.Property("FileCount") + .HasColumnType("integer"); + + b.Property("Gamemode") + .IsRequired() + .HasColumnType("text"); + + b.Property("Link") + .HasColumnType("text"); + + b.Property("Map") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoundEndText") + .HasColumnType("text"); + + b.Property("RoundEndTextSearchVector") + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("tsvector") + .HasAnnotation("Npgsql:TsVectorConfig", "english") + .HasAnnotation("Npgsql:TsVectorProperties", new[] { "RoundEndText" }); + + b.Property("RoundId") + .HasColumnType("integer"); + + b.Property("ServerId") + .IsRequired() + .HasColumnType("text"); + + b.Property("ServerName") + .HasColumnType("text"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("UncompressedSize") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Gamemode"); + + b.HasIndex("Map"); + + b.HasIndex("RoundEndTextSearchVector"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("RoundEndTextSearchVector"), "GIN"); + + b.HasIndex("ServerId"); + + b.HasIndex("ServerName"); + + b.ToTable("Replays", (string)null); + }); + + modelBuilder.Entity("ReplayBrowser.Data.PlayerData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("PlayerGuid") + .HasColumnType("uuid"); + + b.Property("Username") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("PlayerData"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.CharacterData", b => + { + b.HasOne("ReplayBrowser.Data.CollectedPlayerData", null) + .WithMany("Characters") + .HasForeignKey("CollectedPlayerDataPlayerGuid"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.CollectedPlayerData", b => + { + b.HasOne("ReplayBrowser.Data.PlayerData", "PlayerData") + .WithMany() + .HasForeignKey("PlayerDataId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlayerData"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.JobCountData", b => + { + b.HasOne("ReplayBrowser.Data.CollectedPlayerData", null) + .WithMany("JobCount") + .HasForeignKey("CollectedPlayerDataPlayerGuid"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Account.Account", b => + { + b.HasOne("ReplayBrowser.Data.Models.Account.AccountSettings", "Settings") + .WithMany() + .HasForeignKey("SettingsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Settings"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Account.HistoryEntry", b => + { + b.HasOne("ReplayBrowser.Data.Models.Account.Account", null) + .WithMany("History") + .HasForeignKey("AccountId"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Player", b => + { + b.HasOne("ReplayBrowser.Data.Models.Replay", "Replay") + .WithMany("RoundEndPlayers") + .HasForeignKey("ReplayId"); + + b.Navigation("Replay"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.CollectedPlayerData", b => + { + b.Navigation("Characters"); + + b.Navigation("JobCount"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Account.Account", b => + { + b.Navigation("History"); + }); + + modelBuilder.Entity("ReplayBrowser.Data.Models.Replay", b => + { + b.Navigation("RoundEndPlayers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ReplayBrowser/Data/Migrations/20240712104031_RemoveForeignKeysJobCOuntCharData.cs b/ReplayBrowser/Data/Migrations/20240712104031_RemoveForeignKeysJobCOuntCharData.cs new file mode 100644 index 0000000..fc24c85 --- /dev/null +++ b/ReplayBrowser/Data/Migrations/20240712104031_RemoveForeignKeysJobCOuntCharData.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Server.Migrations +{ + /// + public partial class RemoveForeignKeysJobCOuntCharData : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/ReplayBrowser/Data/Migrations/ReplayDbContextModelSnapshot.cs b/ReplayBrowser/Data/Migrations/ReplayDbContextModelSnapshot.cs index 7390d23..69c9566 100644 --- a/ReplayBrowser/Data/Migrations/ReplayDbContextModelSnapshot.cs +++ b/ReplayBrowser/Data/Migrations/ReplayDbContextModelSnapshot.cs @@ -401,11 +401,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("ReplayBrowser.Data.CharacterData", b => { - b.HasOne("ReplayBrowser.Data.CollectedPlayerData", "CollectedPlayerData") + b.HasOne("ReplayBrowser.Data.CollectedPlayerData", null) .WithMany("Characters") .HasForeignKey("CollectedPlayerDataPlayerGuid"); - - b.Navigation("CollectedPlayerData"); }); modelBuilder.Entity("ReplayBrowser.Data.CollectedPlayerData", b => @@ -421,11 +419,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("ReplayBrowser.Data.JobCountData", b => { - b.HasOne("ReplayBrowser.Data.CollectedPlayerData", "CollectedPlayerData") + b.HasOne("ReplayBrowser.Data.CollectedPlayerData", null) .WithMany("JobCount") .HasForeignKey("CollectedPlayerDataPlayerGuid"); - - b.Navigation("CollectedPlayerData"); }); modelBuilder.Entity("ReplayBrowser.Data.Models.Account.Account", b => diff --git a/ReplayBrowser/Services/ProfilePregeneratorService.cs b/ReplayBrowser/Services/ProfilePregeneratorService.cs index a509891..72e425a 100644 --- a/ReplayBrowser/Services/ProfilePregeneratorService.cs +++ b/ReplayBrowser/Services/ProfilePregeneratorService.cs @@ -59,6 +59,8 @@ private void OnReplaysParsed(object? sender, List replays) } } + players = players.Distinct().ToList(); + _queue.Enqueue(players); }