Skip to content

Commit

Permalink
Merge pull request #189 from hltcoe/postgres
Browse files Browse the repository at this point in the history
Fixes #152 by locking additional tasks to avoid an outer join for pg
  • Loading branch information
cash committed Nov 1, 2022
2 parents 88247d8 + ea352fa commit d7391a8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions turkle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction
from django.db import connection, transaction
from django.db.utils import OperationalError
from django.http import JsonResponse
from django.shortcuts import redirect, render
Expand Down Expand Up @@ -146,7 +146,12 @@ def accept_next_task(request, batch_id):

# Lock access to all Tasks available to current user in the batch
# Force evaluation of the query set with len()
len(batch.available_task_ids_for(request.user).select_for_update())
# But postgres does not support select_for_update() with outer join
if connection.vendor != "postgresql":
len(batch.available_task_ids_for(request.user).select_for_update())
else:
# Locks a few more tasks for multiple annotation batches than above
len(batch.unfinished_tasks().select_for_update())

task_id = _skip_aware_next_available_task_id(request, batch)

Expand Down

0 comments on commit d7391a8

Please sign in to comment.