Skip to content

Commit

Permalink
Conditionally apply monkey patch so we work with ZODB4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Jun 14, 2016
1 parent 40ec019 commit b28a004
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions relstorage/__init__.py
Expand Up @@ -29,35 +29,39 @@ def check_compatible():

check_compatible()

try:
import ZODB.mvccadapter # check or ZODB5, which doesn't need the patch
except ImportError:

# def patch_zodb_sync():
# """Patch Connection.sync() and afterCompletion() to pass the 'force' flag.
# """

# def _storage_sync(self, *ignored, **kw):
# if hasattr(self, '_readCurrent'):
# self._readCurrent.clear()
# sync = getattr(self._storage, 'sync', 0)
# if sync:
# # By default, do not force the sync, allowing RelStorage
# # to ignore sync requests for a while.
# force = kw.get('force', False)
# try:
# sync(force=force)
# except TypeError:
# # The 'force' parameter is not accepted.
# sync()
# self._flush_invalidations()

# def sync(self):
# """Manually update the view on the database."""
# self.transaction_manager.abort()
# self._storage_sync(force=True)

# from ZODB.Connection import Connection
# Connection._storage_sync = _storage_sync
# Connection.afterCompletion = _storage_sync
# Connection.newTransaction = _storage_sync
# Connection.sync = sync

# patch_zodb_sync()
def patch_zodb_sync():
"""Patch Connection.sync() and afterCompletion()
to pass the 'force' flag.
"""

def _storage_sync(self, *ignored, **kw):
if hasattr(self, '_readCurrent'):
self._readCurrent.clear()
sync = getattr(self._storage, 'sync', 0)
if sync:
# By default, do not force the sync, allowing RelStorage
# to ignore sync requests for a while.
force = kw.get('force', False)
try:
sync(force=force)
except TypeError:
# The 'force' parameter is not accepted.
sync()
self._flush_invalidations()

def sync(self):
"""Manually update the view on the database."""
self.transaction_manager.abort()
self._storage_sync(force=True)

from ZODB.Connection import Connection
Connection._storage_sync = _storage_sync
Connection.afterCompletion = _storage_sync
Connection.newTransaction = _storage_sync
Connection.sync = sync

patch_zodb_sync()

0 comments on commit b28a004

Please sign in to comment.