diff options
| author | 2023-07-24 13:14:13 +0100 | |
|---|---|---|
| committer | 2023-07-24 13:14:13 +0100 | |
| commit | 9eff0d46e49b947dc2642207ee49ed657eb6b565 (patch) | |
| tree | 62994afff170737d83f1ed911e385504a0ad16cd /internal/db/bundb/search.go | |
| parent | [chore]: Bump github.com/microcosm-cc/bluemonday from 1.0.24 to 1.0.25 (#2021) (diff) | |
| download | gotosocial-9eff0d46e49b947dc2642207ee49ed657eb6b565.tar.xz | |
[feature/performance] support uncaching remote emoji + scheduled cleanup functions (#1987)
Diffstat (limited to 'internal/db/bundb/search.go')
| -rw-r--r-- | internal/db/bundb/search.go | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/internal/db/bundb/search.go b/internal/db/bundb/search.go index c05ebb8b1..1d7eefd48 100644 --- a/internal/db/bundb/search.go +++ b/internal/db/bundb/search.go @@ -19,7 +19,6 @@ package bundb import ( "context" - "strings" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/id" @@ -61,40 +60,6 @@ type searchDB struct { state *state.State } -// replacer is a thread-safe string replacer which escapes -// common SQLite + Postgres `LIKE` wildcard chars using the -// escape character `\`. Initialized as a var in this package -// so it can be reused. -var replacer = strings.NewReplacer( - `\`, `\\`, // Escape char. - `%`, `\%`, // Zero or more char. - `_`, `\_`, // Exactly one char. -) - -// whereSubqueryLike appends a WHERE clause to the -// given SelectQuery q, which searches for matches -// of searchQuery in the given subQuery using LIKE. -func whereSubqueryLike( - q *bun.SelectQuery, - subQuery *bun.SelectQuery, - searchQuery string, -) *bun.SelectQuery { - // Escape existing wildcard + escape - // chars in the search query string. - searchQuery = replacer.Replace(searchQuery) - - // Add our own wildcards back in; search - // zero or more chars around the query. - searchQuery = `%` + searchQuery + `%` - - // Append resulting WHERE - // clause to the main query. - return q.Where( - "(?) LIKE ? ESCAPE ?", - subQuery, searchQuery, `\`, - ) -} - // Query example (SQLite): // // SELECT "account"."id" FROM "accounts" AS "account" @@ -167,7 +132,7 @@ func (s *searchDB) SearchForAccounts( // Search using LIKE for matches of query // string within accountText subquery. - q = whereSubqueryLike(q, accountTextSubq, query) + q = whereLike(q, accountTextSubq, query) if limit > 0 { // Limit amount of accounts returned. @@ -345,7 +310,7 @@ func (s *searchDB) SearchForStatuses( // Search using LIKE for matches of query // string within statusText subquery. - q = whereSubqueryLike(q, statusTextSubq, query) + q = whereLike(q, statusTextSubq, query) if limit > 0 { // Limit amount of statuses returned. |
