Skip to content

Commit

Permalink
Small refactor to avoid duplicate __call__ methods in UseMaster & Use…
Browse files Browse the repository at this point in the history
…Slave
  • Loading branch information
Jay O'Conor committed Jun 23, 2016
1 parent 2aa4b7f commit 0c33abb
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions multidb/pinning.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,12 @@ def __exit__(self, type, value, tb):
use_master = UseMaster()


class UseSlave(object):
class UseSlave(UseMaster):
"""A contextmanager/decorator to use the slave database."""
"Use this in cases where the usual behavior would be to pin to master,"
"such as when the request method is POST, but you know you're not doing any writing."
old = False

def __call__(self, func):
@wraps(func)
def decorator(*args, **kw):
with self:
return func(*args, **kw)
return decorator

def __enter__(self):
self.old = this_thread_is_pinned()
unpin_this_thread()
Expand Down

0 comments on commit 0c33abb

Please sign in to comment.