Compare commits

..

1 Commits

Author SHA1 Message Date
Benjamin Dauvergne a73235b076 misc: add trigram index on unaccented role names (#87906)
gitea/authentic/pipeline/head This commit looks good Details
2024-03-28 22:59:49 +01:00
2 changed files with 12 additions and 1 deletions

View File

@ -405,7 +405,7 @@ class ServiceRoleSearchForm(CssClass, PrefixFormMixin, FormWithRequest):
for word in (w.strip() for w in self.cleaned_data.get('text').split(' ')):
if not word:
continue
qs = qs.filter(name__unaccent__icontains=word)
qs = qs.filter(name__immutable_unaccent__icontains=word)
if not app_settings.SHOW_INTERNAL_ROLES and not self.cleaned_data.get('internals'):
qs = qs.exclude(slug__startswith='_')
return qs

View File

@ -1,4 +1,5 @@
from django.contrib.postgres.lookups import Unaccent as PGUnaccent
from django.db.models import CharField, TextField, Transform
from django.db.models.functions import Concat
from django.db.models.functions import ConcatPair as DjConcatPair
@ -7,6 +8,16 @@ class Unaccent(PGUnaccent):
function = 'immutable_unaccent'
class UnaccentTransform(Transform):
bilateral = True
lookup_name = 'immutable_unaccent'
function = 'immutable_unaccent'
CharField.register_lookup(UnaccentTransform)
TextField.register_lookup(UnaccentTransform)
class ConcatPair(DjConcatPair):
"""Django ConcatPair does not implement as_postgresql, using CONCAT as a default.