Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove select_for_update, it now causes errors with postgres #58

Open
wants to merge 1 commit into
base: remove_wagtail_elasticsearch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions oscar_elasticsearch/search/api/category.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from odin.codecs import dict_codec

from django.db import transaction
from django.db.models import QuerySet

from oscar.core.loading import get_class, get_model

# this index name is retrived with get_class because of i18n but it might be removed later
Expand Down Expand Up @@ -38,16 +35,9 @@ def make_documents(self, objects):
"search.mappings.categories", "CategoryElasticSearchMapping"
)

# the transaction and the select_for_update are candidates for removal!
with transaction.atomic():
if isinstance(objects, QuerySet):
objects = objects.select_for_update()

category_resources = catalogue.CategoryToResource.apply(objects)
category_document_resources = CategoryElasticSearchMapping.apply(
category_resources
)
category_resources = catalogue.CategoryToResource.apply(objects)
category_document_resources = CategoryElasticSearchMapping.apply(
category_resources
)

return dict_codec.dump(
category_document_resources, include_type_field=False
)
return dict_codec.dump(category_document_resources, include_type_field=False)
15 changes: 5 additions & 10 deletions oscar_elasticsearch/search/api/product.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from odin.codecs import dict_codec

from django.db import transaction
from django.db.models import QuerySet

from oscar.core.loading import get_class, get_model, get_classes
Expand Down Expand Up @@ -57,13 +56,9 @@ def make_documents(self, objects):
"search.mappings.products", "ProductElasticSearchMapping"
)

# the transaction and the select_for_update are candidates for removal!
with transaction.atomic():
objects = objects.select_for_update()

product_resources = catalogue.product_queryset_to_resources(objects)
product_document_resources = ProductElasticSearchMapping.apply(
product_resources
)
product_resources = catalogue.product_queryset_to_resources(objects)
product_document_resources = ProductElasticSearchMapping.apply(
product_resources
)

return dict_codec.dump(product_document_resources, include_type_field=False)
return dict_codec.dump(product_document_resources, include_type_field=False)