diff options
author | 2024-02-27 09:18:40 -0800 | |
---|---|---|
committer | 2024-02-27 18:18:40 +0100 | |
commit | ad28b9f16661b36af9c9b4ed0bb2a7740167c934 (patch) | |
tree | fb38a9e77ecd8349b4431b0b0578dba009b745bf /internal/db/bundb/util.go | |
parent | [feature] add script to test import / export cycle of a gotosocial instance (... (diff) | |
download | gotosocial-ad28b9f16661b36af9c9b4ed0bb2a7740167c934.tar.xz |
[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>
Diffstat (limited to 'internal/db/bundb/util.go')
-rw-r--r-- | internal/db/bundb/util.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/db/bundb/util.go b/internal/db/bundb/util.go index e2dd392dc..c7a2b96c2 100644 --- a/internal/db/bundb/util.go +++ b/internal/db/bundb/util.go @@ -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) + }) +} |