Fix search being case sensitive for admin logs from uncached db rounds (#19066)
* Fix search being case sensitive for admin logs from uncached db rounds * Fix text search query for sqlite
This commit is contained in:
@@ -765,9 +765,12 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id}
|
||||
await db.DbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static IQueryable<AdminLog> GetAdminLogsQuery(ServerDbContext db, LogFilter? filter = null)
|
||||
protected abstract IQueryable<AdminLog> StartAdminLogsQuery(ServerDbContext db, LogFilter? filter = null);
|
||||
|
||||
private IQueryable<AdminLog> GetAdminLogsQuery(ServerDbContext db, LogFilter? filter = null)
|
||||
{
|
||||
IQueryable<AdminLog> query = db.AdminLog;
|
||||
// Save me from SQLite
|
||||
var query = StartAdminLogsQuery(db, filter);
|
||||
|
||||
if (filter == null)
|
||||
{
|
||||
@@ -779,11 +782,6 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id}
|
||||
query = query.Where(log => log.RoundId == filter.Round);
|
||||
}
|
||||
|
||||
if (filter.Search != null)
|
||||
{
|
||||
query = query.Where(log => log.Message.Contains(filter.Search));
|
||||
}
|
||||
|
||||
if (filter.Types != null)
|
||||
{
|
||||
query = query.Where(log => filter.Types.Contains(log.Type));
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Shared.CCVar;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Robust.Shared.Configuration;
|
||||
@@ -500,6 +501,21 @@ namespace Content.Server.Database
|
||||
return (admins.Select(p => (p.a, p.LastSeenUserName)).ToArray(), adminRanks)!;
|
||||
}
|
||||
|
||||
protected override IQueryable<AdminLog> StartAdminLogsQuery(ServerDbContext db, LogFilter? filter = null)
|
||||
{
|
||||
// https://learn.microsoft.com/en-us/ef/core/querying/sql-queries#passing-parameters
|
||||
// Read the link above for parameterization before changing this method or you get the bullet
|
||||
if (!string.IsNullOrWhiteSpace(filter?.Search))
|
||||
{
|
||||
return db.AdminLog.FromSql($"""
|
||||
SELECT a.admin_log_id, a.round_id, a.date, a.impact, a.json, a.message, a.type FROM admin_log AS a
|
||||
WHERE to_tsvector('english'::regconfig, a.message) @@ websearch_to_tsquery('english'::regconfig, {filter.Search})
|
||||
""");
|
||||
}
|
||||
|
||||
return db.AdminLog;
|
||||
}
|
||||
|
||||
private async Task<DbGuardImpl> GetDbImpl()
|
||||
{
|
||||
await _dbReadyTask;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.IP;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Shared.CCVar;
|
||||
@@ -478,6 +479,15 @@ namespace Content.Server.Database
|
||||
return round.Id;
|
||||
}
|
||||
|
||||
protected override IQueryable<AdminLog> StartAdminLogsQuery(ServerDbContext db, LogFilter? filter = null)
|
||||
{
|
||||
IQueryable<AdminLog> query = db.AdminLog;
|
||||
if (filter?.Search != null)
|
||||
query = query.Where(log => EF.Functions.Like(log.Message, $"%{filter.Search}%"));
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public override async Task<int> AddAdminNote(AdminNote note)
|
||||
{
|
||||
await using (var db = await GetDb())
|
||||
|
||||
Reference in New Issue
Block a user