summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HBContext.cs7
-rw-r--r--Media.cs4
-rw-r--r--Pages/Gallery.razor5
-rw-r--r--Tag.cs8
4 files changed, 14 insertions, 10 deletions
diff --git a/HBContext.cs b/HBContext.cs
index d0cd26f..f6bc15c 100644
--- a/HBContext.cs
+++ b/HBContext.cs
@@ -4,6 +4,9 @@ using HyperBooru.Services;
namespace HyperBooru;
public class HBContext : DbContext {
+ public const int NsfwTagId = -1;
+ public const int IngestTagId = -2;
+
public static readonly Guid NsfwTag = new("EBDAD4F8-455A-4351-8017-1D4854D6FA38");
public static readonly Guid IngestTag = new("EA212801-5BCC-4C0E-814F-FB9D30DB58BC");
@@ -38,13 +41,13 @@ public class HBContext : DbContext {
// These should NEVER change
modelBuilder.Entity<TagDefinition>().HasData(new TagDefinition[] {
new() {
- ObjectId = -1,
+ ObjectId = NsfwTagId,
Guid = NsfwTag,
Source = TagSource.Internal,
Name = "nsfw"
},
new() {
- ObjectId = -2,
+ ObjectId = IngestTagId,
Guid = IngestTag,
Source = TagSource.Internal,
Name = "ingest"
diff --git a/Media.cs b/Media.cs
index 750aeb4..47aa73b 100644
--- a/Media.cs
+++ b/Media.cs
@@ -14,8 +14,8 @@ public class Media : HBObject {
public virtual List<UploadedFile> UploadedFiles { get; set; } = new();
public bool IsIngest => Tags
- .Select(t => t.TagDefinition.Guid)
- .Contains(HBContext.IngestTag);
+ .Select(t => t.TagDefinitionId)
+ .Contains(HBContext.IngestTagId);
public string? DisplayName {
get {
diff --git a/Pages/Gallery.razor b/Pages/Gallery.razor
index eea051c..e1ca180 100644
--- a/Pages/Gallery.razor
+++ b/Pages/Gallery.razor
@@ -45,7 +45,6 @@
IEnumerable<Media> media = db.Media
.Include(m => m.Tags)
- .ThenInclude(t => t.TagDefinition)
.OrderByDescending(m => m.ObjectId)
.ToArray();
@@ -61,11 +60,11 @@
// Filter both NSFW AND ingest images if we're not showing NSFW
if(!userService.ShowNsfw) {
var nsfwTags = tagService.TagsThatImply(HBContext.NsfwTag)
- .Select(td => td.Guid)
+ .Select(td => td.ObjectId)
.ToArray();
media = media
.AsEnumerable()
- .Where(m => !m.Tags.Select(t => t.TagDefinition.Guid).Intersect(nsfwTags).Any())
+ .Where(m => !m.Tags.Select(t => t.TagDefinitionId).Intersect(nsfwTags).Any())
.Where(m => !m.IsIngest);
}
diff --git a/Tag.cs b/Tag.cs
index 81c5f67..0150b39 100644
--- a/Tag.cs
+++ b/Tag.cs
@@ -18,9 +18,11 @@ public class TagDefinition : HBObject {
}
public class Tag : HBObject {
- public virtual TagDefinition TagDefinition { get; set; }
- public DateTime CreateTime { get; set; } = DateTime.UtcNow;
- public virtual HBObject Target { get; set; }
+ [ForeignKey("ObjectId")]
+ public int TagDefinitionId { get; set; }
+ public virtual TagDefinition TagDefinition { get; set; }
+ public DateTime CreateTime { get; set; } = DateTime.UtcNow;
+ public virtual HBObject Target { get; set; }
public Tag() {}