[backend/database] Remove HTML cache tables

This commit is contained in:
Laura Hausmann 2024-03-01 21:44:06 +01:00
parent ab5258237d
commit b979605470
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
9 changed files with 6242 additions and 153 deletions

View file

@ -39,8 +39,6 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
public virtual DbSet<GalleryLike> GalleryLikes { get; init; } = null!;
public virtual DbSet<GalleryPost> GalleryPosts { get; init; } = null!;
public virtual DbSet<Hashtag> Hashtags { get; init; } = null!;
public virtual DbSet<HtmlNoteCacheEntry> HtmlNoteCacheEntries { get; init; } = null!;
public virtual DbSet<HtmlUserCacheEntry> HtmlUserCacheEntries { get; init; } = null!;
public virtual DbSet<Instance> Instances { get; init; } = null!;
public virtual DbSet<Marker> Markers { get; init; } = null!;
public virtual DbSet<MessagingMessage> MessagingMessages { get; init; } = null!;
@ -469,18 +467,6 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.MentionedUsersCount).HasDefaultValue(0);
});
modelBuilder.Entity<HtmlNoteCacheEntry>(entity =>
{
entity.HasOne(d => d.Note).WithOne(p => p.HtmlNoteCacheEntry);
});
modelBuilder.Entity<HtmlUserCacheEntry>(entity =>
{
entity.Property(e => e.Fields).HasDefaultValueSql("'[]'::jsonb");
entity.HasOne(d => d.User).WithOne(p => p.HtmlUserCacheEntry);
});
modelBuilder.Entity<Instance>(entity =>
{
entity.Property(e => e.CaughtAt).HasComment("The caught date of the Instance.");

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,65 @@
using System;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Iceshrimp.Backend.Core.Database.Migrations
{
/// <inheritdoc />
public partial class RemoveHtmlCache : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "html_note_cache_entry");
migrationBuilder.DropTable(
name: "html_user_cache_entry");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "html_note_cache_entry",
columns: table => new
{
noteId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
content = table.Column<string>(type: "text", nullable: true),
updatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_html_note_cache_entry", x => x.noteId);
table.ForeignKey(
name: "FK_html_note_cache_entry_note_noteId",
column: x => x.noteId,
principalTable: "note",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "html_user_cache_entry",
columns: table => new
{
userId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
bio = table.Column<string>(type: "text", nullable: true),
fields = table.Column<Field[]>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
updatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_html_user_cache_entry", x => x.userId);
table.ForeignKey(
name: "FK_html_user_cache_entry_user_userId",
column: x => x.userId,
principalTable: "user",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
}
}
}

View file

@ -1,7 +1,6 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
using Iceshrimp.Backend.Core.Database;
using Iceshrimp.Backend.Core.Database.Tables;
using Microsoft.EntityFrameworkCore;
@ -1581,53 +1580,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.ToTable("hashtag");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.HtmlNoteCacheEntry", b =>
{
b.Property<string>("NoteId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("noteId");
b.Property<string>("Content")
.HasColumnType("text")
.HasColumnName("content");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("updatedAt");
b.HasKey("NoteId");
b.ToTable("html_note_cache_entry");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.HtmlUserCacheEntry", b =>
{
b.Property<string>("UserId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("userId");
b.Property<string>("Bio")
.HasColumnType("text")
.HasColumnName("bio");
b.Property<Field[]>("Fields")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("jsonb")
.HasColumnName("fields")
.HasDefaultValueSql("'[]'::jsonb");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("updatedAt");
b.HasKey("UserId");
b.ToTable("html_user_cache_entry");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Instance", b =>
{
b.Property<string>("Id")
@ -1650,18 +1602,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
.HasColumnType("character varying(4096)")
.HasColumnName("faviconUrl");
b.Property<int>("FollowersCount")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(0)
.HasColumnName("outgoingFollows");
b.Property<int>("FollowingCount")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(0)
.HasColumnName("incomingFollows");
b.Property<string>("Host")
.IsRequired()
.HasMaxLength(512)
@ -1674,6 +1614,12 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
.HasColumnType("character varying(4096)")
.HasColumnName("iconUrl");
b.Property<int>("IncomingFollows")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(0)
.HasColumnName("incomingFollows");
b.Property<DateTime?>("InfoUpdatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("infoUpdatedAt");
@ -1732,6 +1678,12 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
.HasColumnType("boolean")
.HasColumnName("openRegistrations");
b.Property<int>("OutgoingFollows")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(0)
.HasColumnName("outgoingFollows");
b.Property<string>("SoftwareName")
.HasMaxLength(64)
.HasColumnType("character varying(64)")
@ -5294,28 +5246,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.HtmlNoteCacheEntry", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.Note", "Note")
.WithOne("HtmlNoteCacheEntry")
.HasForeignKey("Iceshrimp.Backend.Core.Database.Tables.HtmlNoteCacheEntry", "NoteId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Note");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.HtmlUserCacheEntry", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
.WithOne("HtmlUserCacheEntry")
.HasForeignKey("Iceshrimp.Backend.Core.Database.Tables.HtmlUserCacheEntry", "UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Marker", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
@ -6035,8 +5965,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("ClipNotes");
b.Navigation("HtmlNoteCacheEntry");
b.Navigation("InverseRenote");
b.Navigation("InverseReply");
@ -6112,8 +6040,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("GalleryPosts");
b.Navigation("HtmlUserCacheEntry");
b.Navigation("IncomingBlocks");
b.Navigation("IncomingFollowRelationships");

View file

@ -1,21 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("html_note_cache_entry")]
public class HtmlNoteCacheEntry
{
[Key]
[Column("noteId")]
[StringLength(32)]
public string NoteId { get; set; } = null!;
[Column("updatedAt")] public DateTime? UpdatedAt { get; set; }
[Column("content")] public string? Content { get; set; }
[ForeignKey("NoteId")]
[InverseProperty(nameof(Tables.Note.HtmlNoteCacheEntry))]
public virtual Note Note { get; set; } = null!;
}

View file

@ -1,24 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("html_user_cache_entry")]
public class HtmlUserCacheEntry
{
[Key]
[Column("userId")]
[StringLength(32)]
public string UserId { get; set; } = null!;
[Column("updatedAt")] public DateTime? UpdatedAt { get; set; }
[Column("bio")] public string? Bio { get; set; }
[Column("fields", TypeName = "jsonb")] public Field[] Fields { get; set; } = null!;
[ForeignKey("UserId")]
[InverseProperty(nameof(Tables.User.HtmlUserCacheEntry))]
public virtual User User { get; set; } = null!;
}

View file

@ -190,9 +190,6 @@ public class Note : IEntity
[InverseProperty(nameof(ClipNote.Note))]
public virtual ICollection<ClipNote> ClipNotes { get; set; } = new List<ClipNote>();
[InverseProperty(nameof(Tables.HtmlNoteCacheEntry.Note))]
public virtual HtmlNoteCacheEntry? HtmlNoteCacheEntry { get; set; }
[InverseProperty(nameof(Renote))] public virtual ICollection<Note> InverseRenote { get; set; } = new List<Note>();
[InverseProperty(nameof(Reply))] public virtual ICollection<Note> InverseReply { get; set; } = new List<Note>();

View file

@ -358,9 +358,6 @@ public class User : IEntity
[InverseProperty(nameof(GalleryPost.User))]
public virtual ICollection<GalleryPost> GalleryPosts { get; set; } = new List<GalleryPost>();
[InverseProperty(nameof(Tables.HtmlUserCacheEntry.User))]
public virtual HtmlUserCacheEntry? HtmlUserCacheEntry { get; set; }
[InverseProperty(nameof(Marker.User))]
public virtual ICollection<Marker> Markers { get; set; } = new List<Marker>();

View file

@ -2,11 +2,9 @@ using AsyncKeyedLock;
using Iceshrimp.Backend.Core.Configuration;
using Iceshrimp.Backend.Core.Database;
using Iceshrimp.Backend.Core.Database.Tables;
using Iceshrimp.Backend.Core.Extensions;
using Iceshrimp.Backend.Core.Federation.WebFinger;
using Iceshrimp.Backend.Core.Middleware;
using Iceshrimp.Backend.Core.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Iceshrimp.Backend.Core.Federation.ActivityPub;