[bugfix] Account timeline: exclude self-replies that mention other accounts (#2670)

* Account timeline: exclude self-replies that mention other accounts

* Add index for querying unmentioned statuses

* remove now unused statuses_account_id_id_idx

---------

Co-authored-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
Vyr Cossont 2024-02-27 09:18:40 -08:00 committed by GitHub
commit ad28b9f166
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 212 additions and 1 deletions

View file

@ -206,3 +206,23 @@ func parseWhere(w db.Where) (query string, args []interface{}) {
args = []interface{}{bun.Ident(w.Key), w.Value}
return
}
// whereArrayIsNullOrEmpty extends a query with a where clause requiring an array to be null or empty.
// (The empty check varies by dialect; only PG has direct support for SQL array types.)
func whereArrayIsNullOrEmpty(query *bun.SelectQuery, subject interface{}) *bun.SelectQuery {
var arrayEmptySQL string
switch d := query.Dialect().Name(); d {
case dialect.SQLite:
arrayEmptySQL = "json_array_length(?) = 0"
case dialect.PG:
arrayEmptySQL = "CARDINALITY(?) = 0"
default:
log.Panicf(nil, "db conn %s was neither pg nor sqlite", d)
}
return query.WhereGroup(" AND ", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.
Where("? IS NULL", subject).
WhereOr(arrayEmptySQL, subject)
})
}