[Backport] Making update_attr_in_bulk_for_ids work in asynch mode if possible

remotes/origin/3.4.0rc
Alejandro Alonso 2017-05-09 12:27:10 +02:00 committed by Jesús Espino
parent 4d59996620
commit 74a8e8e365
1 changed files with 12 additions and 2 deletions

View File

@ -16,11 +16,13 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import connection from django.db import connection
from django.db import DatabaseError from django.db import DatabaseError
from django.db import transaction from django.db import transaction
from django.shortcuts import _get_queryset from django.shortcuts import _get_queryset
from taiga.celery import app
from . import functions from . import functions
@ -122,9 +124,9 @@ def update_in_bulk(instances, list_of_new_values, callback=None, precall=None):
instance.save() instance.save()
callback(instance) callback(instance)
@app.task
@transaction.atomic @transaction.atomic
def update_attr_in_bulk_for_ids(values, attr, model): def _update_attr_in_bulk_for_ids(values, attr, model):
"""Update a table using a list of ids. """Update a table using a list of ids.
:params values: Dict of new values where the key is the pk of the element to update. :params values: Dict of new values where the key is the pk of the element to update.
@ -162,6 +164,14 @@ def update_attr_in_bulk_for_ids(values, attr, model):
transaction.on_commit(_run_sql) transaction.on_commit(_run_sql)
@transaction.atomic
def update_attr_in_bulk_for_ids(values, attr, model):
if settings.CELERY_ENABLED:
_update_attr_in_bulk_for_ids.delay(values, attr, model)
else:
_update_attr_in_bulk_for_ids(values, attr, model)
def to_tsquery(term): def to_tsquery(term):
""" """
Based on: https://gist.github.com/wolever/1a5ccf6396f00229b2dc Based on: https://gist.github.com/wolever/1a5ccf6396f00229b2dc