Implement count estimate query for postgresdb (#7956)
This commit is contained in:
@@ -174,6 +174,8 @@ namespace Content.Server.Database
|
||||
{
|
||||
return query.Where(log => EF.Functions.Like(log.Message, "%" + searchText + "%"));
|
||||
}
|
||||
|
||||
public abstract int CountAdminLogs();
|
||||
}
|
||||
|
||||
public class Preference
|
||||
|
||||
@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using NpgsqlTypes;
|
||||
using Npgsql;
|
||||
|
||||
namespace Content.Server.Database
|
||||
{
|
||||
@@ -80,5 +80,15 @@ namespace Content.Server.Database
|
||||
{
|
||||
return query.Where(log => EF.Functions.ToTsVector("english", log.Message).Matches(searchText));
|
||||
}
|
||||
|
||||
public override int CountAdminLogs()
|
||||
{
|
||||
using var command = new NpgsqlCommand("SELECT reltuples FROM pg_class WHERE relname = 'admin_log';", (NpgsqlConnection?) Database.GetDbConnection());
|
||||
|
||||
Database.GetDbConnection().Open();
|
||||
var count = Convert.ToInt32((float) (command.ExecuteScalar() ?? 0));
|
||||
Database.GetDbConnection().Close();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
@@ -81,6 +82,11 @@ namespace Content.Server.Database
|
||||
.HasConversion(jsonByteArrayConverter);
|
||||
}
|
||||
|
||||
public override int CountAdminLogs()
|
||||
{
|
||||
return AdminLog.Count();
|
||||
}
|
||||
|
||||
private static string InetToString(IPAddress address, int mask) {
|
||||
if (address.IsIPv4MappedToIPv6)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user