PostgreSQL: Limit document size to 650kb

This commit is contained in:
mdecimus
2025-12-27 16:55:25 +01:00
parent e03629d1d2
commit 5e9d78567d
2 changed files with 46 additions and 6 deletions

View File

@@ -318,9 +318,8 @@ impl ToSql for SearchValue {
SearchValue::Text { value, .. } => {
// Truncate large text fields to avoid Postgres errors (see https://www.postgresql.org/docs/current/textsearch-limitations.html)
if value.len() > 1_048_574 {
let pos = value.floor_char_boundary(1_048_574);
(&value[..pos]).to_sql(ty, out)
if value.len() > 650_000 {
(&value[..value.floor_char_boundary(650_000)]).to_sql(ty, out)
} else {
value.to_sql(ty, out)
}
@@ -356,9 +355,8 @@ impl ToSql for SearchValue {
SearchValue::Text { value, .. } => {
// Truncate large text fields to avoid Postgres errors (see https://www.postgresql.org/docs/current/textsearch-limitations.html)
if value.len() > 1_048_574 {
let pos = value.floor_char_boundary(1_048_574);
(&value[..pos]).to_sql_checked(ty, out)
if value.len() > 650_000 {
(&value[..value.floor_char_boundary(650_000)]).to_sql_checked(ty, out)
} else {
value.to_sql_checked(ty, out)
}