Implement count estimate query for postgresdb (#7956)

This commit is contained in:
Julian Giebel
2022-05-06 16:04:33 +02:00
committed by GitHub
parent 382baa7bdd
commit 288f66d8c4
3 changed files with 19 additions and 1 deletions

View File

@@ -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;
}
}
}