🗑️ Remove the shit simple search vector
This commit is contained in:
@@ -70,8 +70,6 @@ public class SnPost : ModelBase, IIdentifiedResource, IActivity
|
|||||||
|
|
||||||
[Column(TypeName = "jsonb")] public List<SnCloudFileReferenceObject> Attachments { get; set; } = [];
|
[Column(TypeName = "jsonb")] public List<SnCloudFileReferenceObject> Attachments { get; set; } = [];
|
||||||
|
|
||||||
[JsonIgnore] public NpgsqlTsVector SearchVector { get; set; } = null!;
|
|
||||||
|
|
||||||
public Guid PublisherId { get; set; }
|
public Guid PublisherId { get; set; }
|
||||||
public SnPublisher Publisher { get; set; } = null!;
|
public SnPublisher Publisher { get; set; } = null!;
|
||||||
|
|
||||||
|
|||||||
@@ -82,11 +82,6 @@ public class AppDatabase(
|
|||||||
.HasForeignKey(ps => ps.PublisherId)
|
.HasForeignKey(ps => ps.PublisherId)
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
modelBuilder.Entity<SnPost>()
|
|
||||||
.HasGeneratedTsVectorColumn(p => p.SearchVector, "simple", p => new { p.Title, p.Description, p.Content })
|
|
||||||
.HasIndex(p => p.SearchVector)
|
|
||||||
.HasMethod("GIN");
|
|
||||||
|
|
||||||
modelBuilder.Entity<SnPost>()
|
modelBuilder.Entity<SnPost>()
|
||||||
.HasOne(p => p.RepliedPost)
|
.HasOne(p => p.RepliedPost)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
|
|||||||
1930
DysonNetwork.Sphere/Migrations/20251025184407_RemovePostSearchVector.Designer.cs
generated
Normal file
1930
DysonNetwork.Sphere/Migrations/20251025184407_RemovePostSearchVector.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using NpgsqlTypes;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Sphere.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RemovePostSearchVector : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "ix_posts_search_vector",
|
||||||
|
table: "posts");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "search_vector",
|
||||||
|
table: "posts");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<NpgsqlTsVector>(
|
||||||
|
name: "search_vector",
|
||||||
|
table: "posts",
|
||||||
|
type: "tsvector",
|
||||||
|
nullable: false)
|
||||||
|
.Annotation("Npgsql:TsVectorConfig", "simple")
|
||||||
|
.Annotation("Npgsql:TsVectorProperties", new[] { "title", "description", "content" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "ix_posts_search_vector",
|
||||||
|
table: "posts",
|
||||||
|
column: "search_vector")
|
||||||
|
.Annotation("Npgsql:IndexMethod", "GIN");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
|||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
using NpgsqlTypes;
|
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
@@ -531,14 +530,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
.HasColumnType("uuid")
|
.HasColumnType("uuid")
|
||||||
.HasColumnName("replied_post_id");
|
.HasColumnName("replied_post_id");
|
||||||
|
|
||||||
b.Property<NpgsqlTsVector>("SearchVector")
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAddOrUpdate()
|
|
||||||
.HasColumnType("tsvector")
|
|
||||||
.HasColumnName("search_vector")
|
|
||||||
.HasAnnotation("Npgsql:TsVectorConfig", "simple")
|
|
||||||
.HasAnnotation("Npgsql:TsVectorProperties", new[] { "Title", "Description", "Content" });
|
|
||||||
|
|
||||||
b.Property<List<ContentSensitiveMark>>("SensitiveMarks")
|
b.Property<List<ContentSensitiveMark>>("SensitiveMarks")
|
||||||
.HasColumnType("jsonb")
|
.HasColumnType("jsonb")
|
||||||
.HasColumnName("sensitive_marks");
|
.HasColumnName("sensitive_marks");
|
||||||
@@ -589,11 +580,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
b.HasIndex("RepliedPostId")
|
b.HasIndex("RepliedPostId")
|
||||||
.HasDatabaseName("ix_posts_replied_post_id");
|
.HasDatabaseName("ix_posts_replied_post_id");
|
||||||
|
|
||||||
b.HasIndex("SearchVector")
|
|
||||||
.HasDatabaseName("ix_posts_search_vector");
|
|
||||||
|
|
||||||
NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("SearchVector"), "GIN");
|
|
||||||
|
|
||||||
b.ToTable("posts", (string)null);
|
b.ToTable("posts", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using DysonNetwork.Shared.Models;
|
|||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
using DysonNetwork.Shared.Registry;
|
using DysonNetwork.Shared.Registry;
|
||||||
using DysonNetwork.Sphere.Poll;
|
using DysonNetwork.Sphere.Poll;
|
||||||
|
|
||||||
using DysonNetwork.Sphere.WebReader;
|
using DysonNetwork.Sphere.WebReader;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -85,7 +84,6 @@ public class PostController(
|
|||||||
[FromQuery(Name = "categories")] List<string>? categories = null,
|
[FromQuery(Name = "categories")] List<string>? categories = null,
|
||||||
[FromQuery(Name = "tags")] List<string>? tags = null,
|
[FromQuery(Name = "tags")] List<string>? tags = null,
|
||||||
[FromQuery(Name = "query")] string? queryTerm = null,
|
[FromQuery(Name = "query")] string? queryTerm = null,
|
||||||
[FromQuery(Name = "vector")] bool queryVector = false,
|
|
||||||
[FromQuery(Name = "media")] bool onlyMedia = false,
|
[FromQuery(Name = "media")] bool onlyMedia = false,
|
||||||
[FromQuery(Name = "shuffle")] bool shuffle = false,
|
[FromQuery(Name = "shuffle")] bool shuffle = false,
|
||||||
[FromQuery(Name = "replies")] bool? includeReplies = null,
|
[FromQuery(Name = "replies")] bool? includeReplies = null,
|
||||||
@@ -99,7 +97,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
{ AccountId = currentUser.Id });
|
{ AccountId = currentUser.Id });
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,14 +159,11 @@ public class PostController(
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(queryTerm))
|
if (!string.IsNullOrWhiteSpace(queryTerm))
|
||||||
{
|
{
|
||||||
if (queryVector)
|
query = query.Where(p =>
|
||||||
query = query.Where(p => p.SearchVector.Matches(EF.Functions.ToTsQuery(queryTerm)));
|
(p.Title != null && EF.Functions.ILike(p.Title, $"%{queryTerm}%")) ||
|
||||||
else
|
(p.Description != null && EF.Functions.ILike(p.Description, $"%{queryTerm}%")) ||
|
||||||
query = query.Where(p =>
|
(p.Content != null && EF.Functions.ILike(p.Content, $"%{queryTerm}%"))
|
||||||
(p.Title != null && EF.Functions.ILike(p.Title, $"%{queryTerm}%")) ||
|
);
|
||||||
(p.Description != null && EF.Functions.ILike(p.Description, $"%{queryTerm}%")) ||
|
|
||||||
(p.Content != null && EF.Functions.ILike(p.Content, $"%{queryTerm}%"))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
query = query
|
query = query
|
||||||
@@ -221,7 +216,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
{ AccountId = currentUser.Id });
|
{ AccountId = currentUser.Id });
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +249,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
{ AccountId = currentUser.Id });
|
{ AccountId = currentUser.Id });
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +316,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
{ AccountId = currentUser.Id });
|
{ AccountId = currentUser.Id });
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +347,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
{ AccountId = currentUser.Id });
|
{ AccountId = currentUser.Id });
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +375,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
{ AccountId = currentUser.Id });
|
{ AccountId = currentUser.Id });
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,7 +575,7 @@ public class PostController(
|
|||||||
|
|
||||||
var friendsResponse =
|
var friendsResponse =
|
||||||
await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
{ AccountId = currentUser.Id.ToString() });
|
{ AccountId = currentUser.Id.ToString() });
|
||||||
var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
||||||
|
|
||||||
@@ -676,7 +671,7 @@ public class PostController(
|
|||||||
|
|
||||||
var friendsResponse =
|
var friendsResponse =
|
||||||
await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
{ AccountId = currentUser.Id.ToString() });
|
{ AccountId = currentUser.Id.ToString() });
|
||||||
var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user