From be96a6c7ba634640a5d814ab0a4b8a912e32423e Mon Sep 17 00:00:00 2001 From: dormantman Date: Fri, 17 Jan 2020 17:29:58 +0300 Subject: [PATCH 1/3] Added type for pop filter in tags --- apps/tag/views.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/tag/views.py b/apps/tag/views.py index c621cd71..f526b572 100644 --- a/apps/tag/views.py +++ b/apps/tag/views.py @@ -129,10 +129,19 @@ class FiltersTagCategoryViewSet(TagCategoryViewSet): result_list.append(wine_regions) + item_types = { + 'pop': 'pop' + } + for item in result_list: if 'filters' in item: item['filters'].sort(key=lambda x: x.get('label_translated')) + index_name = item.get('index_name') + + if index_name in item_types: + item['type'] = item_types[index_name] + if filter_flags['toque_number']: toques = { "index_name": "toque_number", @@ -206,7 +215,7 @@ class FiltersTagCategoryViewSet(TagCategoryViewSet): result_list = [category for category in result_list if category.get('index_name') != 'tag'] if len(tag_category): tag_category = list(filter(lambda x: x.get('index_name') == 'pop', tag_category[0]['filters'])) - if len(tag_category): # we have Pop tag in our results + if len(tag_category): # we have Pop tag in our results tag_category = tag_category[0] tag_category['param_name'] = 'tags_id__in' result_list.append(tag_category) From 51114b0e9564c46cb5ad5b5a4d36d6cb591344f5 Mon Sep 17 00:00:00 2001 From: dormantman Date: Sat, 18 Jan 2020 01:04:30 +0300 Subject: [PATCH 2/3] Added db index to siteinterfacedictionary text for optimize --- .../migrations/0008_index_siteifdict_text.py | 18 ++++++++++++++++++ apps/translation/models.py | 4 ++++ 2 files changed, 22 insertions(+) create mode 100644 apps/translation/migrations/0008_index_siteifdict_text.py diff --git a/apps/translation/migrations/0008_index_siteifdict_text.py b/apps/translation/migrations/0008_index_siteifdict_text.py new file mode 100644 index 00000000..b5b485ec --- /dev/null +++ b/apps/translation/migrations/0008_index_siteifdict_text.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.7 on 2020-01-17 22:01 + +import django.contrib.postgres.indexes +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('translation', '0007_language_is_active'), + ] + + operations = [ + migrations.AddIndex( + model_name='siteinterfacedictionary', + index=django.contrib.postgres.indexes.GinIndex(fields=['text'], name='translation_text_0b2bfa_gin'), + ), + ] diff --git a/apps/translation/models.py b/apps/translation/models.py index a288b334..86e5e52a 100644 --- a/apps/translation/models.py +++ b/apps/translation/models.py @@ -1,5 +1,6 @@ """Translation app models.""" from django.contrib.postgres.fields import JSONField +from django.contrib.postgres.indexes import GinIndex from django.db import models from django.utils.translation import gettext_lazy as _ from django.apps import apps @@ -105,6 +106,9 @@ class SiteInterfaceDictionary(ProjectBaseMixin): verbose_name = _('Site interface dictionary') verbose_name_plural = _('Site interface dictionary') + indexes = [ + GinIndex(fields=['text']) + ] def __str__(self): return f'{self.page}: {self.keywords}' From f9d4d4ff575f432a4333906133391210853b88fe Mon Sep 17 00:00:00 2001 From: dormantman Date: Sat, 18 Jan 2020 01:05:44 +0300 Subject: [PATCH 3/3] Revert "Added type for pop filter in tags" This reverts commit be96a6c7 --- apps/tag/views.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/apps/tag/views.py b/apps/tag/views.py index f526b572..c621cd71 100644 --- a/apps/tag/views.py +++ b/apps/tag/views.py @@ -129,19 +129,10 @@ class FiltersTagCategoryViewSet(TagCategoryViewSet): result_list.append(wine_regions) - item_types = { - 'pop': 'pop' - } - for item in result_list: if 'filters' in item: item['filters'].sort(key=lambda x: x.get('label_translated')) - index_name = item.get('index_name') - - if index_name in item_types: - item['type'] = item_types[index_name] - if filter_flags['toque_number']: toques = { "index_name": "toque_number", @@ -215,7 +206,7 @@ class FiltersTagCategoryViewSet(TagCategoryViewSet): result_list = [category for category in result_list if category.get('index_name') != 'tag'] if len(tag_category): tag_category = list(filter(lambda x: x.get('index_name') == 'pop', tag_category[0]['filters'])) - if len(tag_category): # we have Pop tag in our results + if len(tag_category): # we have Pop tag in our results tag_category = tag_category[0] tag_category['param_name'] = 'tags_id__in' result_list.append(tag_category)