import django_filters
import graphene

from ...menu.models import Menu, MenuItem
from ..core.filters import ListObjectTypeFilter, MetadataFilterBase
from ..core.types import FilterInputObjectType
from ..utils.filters import filter_by_query_param


def filter_menu_search(qs, _, value):
    menu_fields = ["name", "slug"]
    qs = filter_by_query_param(qs, value, menu_fields)
    return qs


def filter_menu_slug(qs, _, value):
    return qs.filter(slug__in=value)


def filter_menu_item_search(qs, _, value):
    menu_item_fields = ["name"]
    qs = filter_by_query_param(qs, value, menu_item_fields)
    return qs


class MenuFilter(MetadataFilterBase):
    search = django_filters.CharFilter(method=filter_menu_search)
    slug = ListObjectTypeFilter(input_class=graphene.String, method=filter_menu_slug)

    class Meta:
        model = Menu
        fields = ["search", "slug"]


class MenuItemFilter(MetadataFilterBase):
    search = django_filters.CharFilter(method=filter_menu_item_search)

    class Meta:
        model = MenuItem
        fields = ["search"]


class MenuFilterInput(FilterInputObjectType):
    class Meta:
        filterset_class = MenuFilter


class MenuItemFilterInput(FilterInputObjectType):
    class Meta:
        filterset_class = MenuItemFilter

@@ -30,16 +30,47 @@
 graphene
+%0Afrom django.db.models import Q
 %0A%0Afrom .
@@ -224,201 +224,113 @@
 ype%0A
-from ..utils.filters import filter_by_query_param%0A%0A%0Adef filter_menu_search(qs, _, value):%0A    menu_fields = %5B%22name%22, %22slug%22%5D%0A    qs = filter_by_query_param(qs, value, menu_fields)%0A    return qs
+%0A%0Adef filter_menu_search(qs, _, value):%0A    return qs.filter(Q(name__ilike=value) %7C Q(slug__ilike=value))
 %0A%0A%0Ad
@@ -454,109 +454,43 @@
     
-menu_item_fields = %5B%22name%22%5D%0A    qs = filter_by_query_param(qs, value, menu_item_fields)%0A    return qs
+return qs.filter(name__ilike=value)
 %0A%0A%0Ac

Improve menus filtering performance