Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Adjust settings to use new pinning database router and middleware.
Browse files Browse the repository at this point in the history
Audit forum views for master-slave race conditions. Added a few comments about possible ones but didn't find any that can't be equally caused by our autocommitting.
  • Loading branch information
erikrose committed Jun 18, 2010
1 parent 0856843 commit 203e06c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
13 changes: 12 additions & 1 deletion apps/forums/views.py
Expand Up @@ -104,6 +104,11 @@ def reply(request, forum_slug, thread_id):
if form.is_valid():
forum = get_object_or_404(Forum, slug=forum_slug)
thread = get_object_or_404(Thread, pk=thread_id, forum=forum)

# A reply or two might sneak in after the thread is locked due to
# replication lag, but that should be very rare and won't result in a
# user-visible error. Not worth pinning to master as long as we're not
# even using one transaction per request.
if not thread.is_locked:
reply_ = form.save(commit=False)
reply_.thread = thread
Expand Down Expand Up @@ -167,6 +172,9 @@ def lock_thread(request, forum_slug, thread_id):
(Forum, 'slug__iexact', 'forum_slug'))
def sticky_thread(request, forum_slug, thread_id):
"""Mark/unmark a thread sticky."""
# TODO: Have a separate sticky_thread() and unsticky_thread() to avoid a
# race condition where a double-bounce on the "sticky" button sets it
# sticky and then unsticky. [572836]

forum = get_object_or_404(Forum, slug=forum_slug)
thread = get_object_or_404(Thread, pk=thread_id, forum=forum)
Expand Down Expand Up @@ -302,7 +310,10 @@ def delete_post(request, forum_slug, thread_id, post_id):
@login_required
@require_POST
def watch_thread(request, forum_slug, thread_id):
"""Start watching a thread."""
"""Toggle whether a thread is being watched."""
# TODO: Have a separate watch_thread() and unwatch_thread() to avoid a
# race condition where a double-bounce on the "watch" button watches and
# then unwatches a thread. [572836]

forum = get_object_or_404(Forum, slug=forum_slug)
thread = get_object_or_404(Thread, pk=thread_id, forum=forum)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,5 +1,5 @@
-e svn+http://code.djangoproject.com/svn/django/trunk@13302#egg=Django
-e git://github.com/jbalogh/django-multidb-router.git@8eeef712a2f594d9fe6ba1e2ffc9240814d6a185#egg=django-multidb-router
-e git://github.com/jbalogh/django-multidb-router.git@25ca0c68929144ed9020d89f2ea1e941c7f9aeca#egg=django-multidb-router
-e git://github.com/jbalogh/django-cache-machine.git@bdee25ba4eeb20758da86f4013edbc48a77bcc6e#egg=django-cache-machine
-e git://github.com/django-extensions/django-extensions.git#egg=django_extensions
Jinja2==2.2.1
Expand Down
3 changes: 2 additions & 1 deletion settings.py
Expand Up @@ -33,7 +33,7 @@
}
}

DATABASE_ROUTERS = ('multidb.MasterSlaveRouter',)
DATABASE_ROUTERS = ('multidb.PinningMasterSlaveRouter',)

# Put the aliases for your slave databases in this list
SLAVE_DATABASES = []
Expand Down Expand Up @@ -122,6 +122,7 @@
)

MIDDLEWARE_CLASSES = (
'multidb.middleware.PinningRouterMiddleware',
'sumo.middleware.LocaleURLMiddleware',
'sumo.middleware.Forbidden403Middleware',
'django.middleware.common.CommonMiddleware',
Expand Down

0 comments on commit 203e06c

Please sign in to comment.