Skip to content

Commit

Permalink
fix: update limit for es response
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-D-Akbar committed Mar 29, 2024
1 parent df07d96 commit 505e741
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
12 changes: 4 additions & 8 deletions course_discovery/apps/api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2624,8 +2624,7 @@ def get_expected_data(cls, person, request):


@pytest.mark.django_db
@pytest.mark.usefixtures('elasticsearch_dsl_default_connection')
class TestProgramSearchDocumentSerializer(TestCase):
class TestProgramSearchDocumentSerializer(ElasticsearchTestMixin, TestCase):
serializer_class = ProgramSearchDocumentSerializer

def setUp(self):
Expand Down Expand Up @@ -2723,8 +2722,7 @@ def get_expected_data(cls, program, request):


@pytest.mark.django_db
@pytest.mark.usefixtures('elasticsearch_dsl_default_connection')
class TestLearnerPathwaySearchDocumentSerializer(TestCase):
class TestLearnerPathwaySearchDocumentSerializer(ElasticsearchTestMixin, TestCase):
serializer_class = LearnerPathwaySearchDocumentSerializer

def setUp(self):
Expand Down Expand Up @@ -2783,8 +2781,7 @@ def get_expected_data(cls, learner_pathway, request):


@pytest.mark.django_db
@pytest.mark.usefixtures('elasticsearch_dsl_default_connection')
class TestTypeaheadCourseRunSearchSerializer:
class TestTypeaheadCourseRunSearchSerializer(ElasticsearchTestMixin, TestCase):
serializer_class = TypeaheadCourseRunSearchSerializer

@classmethod
Expand All @@ -2810,8 +2807,7 @@ def serialize_course_run(self, course_run):


@pytest.mark.django_db
@pytest.mark.usefixtures('elasticsearch_dsl_default_connection')
class TestTypeaheadProgramSearchSerializer:
class TestTypeaheadProgramSearchSerializer(ElasticsearchTestMixin, TestCase):
serializer_class = TypeaheadProgramSearchSerializer

@classmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import urllib

from rest_framework.reverse import reverse
Expand All @@ -8,6 +9,7 @@
from course_discovery.apps.course_metadata.tests.factories import CourseFactory, CourseRunFactory


@pytest.mark.django_db
class CatalogQueryViewSetTests(ElasticsearchTestMixin, APITestCase):
def setUp(self):
super().setUp()
Expand Down
1 change: 1 addition & 0 deletions course_discovery/apps/core/tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ElasticsearchTestMixin:
def setUp(self):
super().setUp()
self.es = get_connection()
self.es.indices.put_settings(body={"index": {"max_result_window": settings.MAX_RESULT_WINDOW}})

def refresh_index(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def _create(self, models, aliases, options):
)
)
ElasticsearchUtils.set_alias(es_connection, created_index_info.alias, created_index_info.name)
es_connection = get_connection()
es_connection.indices.put_settings(body={"index": {"max_result_window": settings.MAX_RESULT_WINDOW}})

def _delete(self, models, aliases, options):
# pylint: disable=protected-access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def _update(self, models, options):
for index_alias_mapper in alias_mappings:
index_alias_mapper.registered_index._name = index_alias_mapper.alias # pylint: disable=protected-access

conn.indices.put_settings(body={"index": {"max_result_window": settings.MAX_RESULT_WINDOW}})

if indexes_pending:
raise CommandError('Sanity check failed for the new index(es): {}'.format(indexes_pending))

Expand Down
6 changes: 4 additions & 2 deletions course_discovery/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,13 @@
# (by default it uses the database driver's default setting)
# https://docs.djangoproject.com/en/3.1/ref/models/querysets/#iterator
# Thus set the 'chunk_size'
ELASTICSEARCH_DSL_QUERYSET_PAGINATION = 10000
ELASTICSEARCH_DSL_QUERYSET_PAGINATION = 15000

# Defining default pagination for all requests to ElasticSearch,
# whose parameters 'size' and 'from' are not explicitly set.
ELASTICSEARCH_DSL_LOAD_PER_QUERY = 10000
ELASTICSEARCH_DSL_LOAD_PER_QUERY = 15000

MAX_RESULT_WINDOW = 15000

ELASTICSEARCH_DSL = {
'default': {'hosts': '127.0.0.1:9200'}
Expand Down

0 comments on commit 505e741

Please sign in to comment.