[CalendarServer-changes] [7258] CalendarServer/branches/users/glyph/subtransactions/txdav/base/ propertystore/sql.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 24 13:37:13 PDT 2011
Revision: 7258
http://trac.macosforge.org/projects/calendarserver/changeset/7258
Author: glyph at apple.com
Date: 2011-03-24 13:37:12 -0700 (Thu, 24 Mar 2011)
Log Message:
-----------
make the test pass, with subtransactions
Modified Paths:
--------------
CalendarServer/branches/users/glyph/subtransactions/txdav/base/propertystore/sql.py
Modified: CalendarServer/branches/users/glyph/subtransactions/txdav/base/propertystore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/subtransactions/txdav/base/propertystore/sql.py 2011-03-24 20:37:02 UTC (rev 7257)
+++ CalendarServer/branches/users/glyph/subtransactions/txdav/base/propertystore/sql.py 2011-03-24 20:37:12 UTC (rev 7258)
@@ -55,6 +55,23 @@
Where=prop.RESOURCE_ID == Parameter("resourceID"))
+ @inlineCallbacks
+ def _refresh(self, txn):
+ """
+ Load, or re-load, this object with the given transaction; first from
+ memcache, then pulling from the database again.
+ """
+ # Cache existing properties in this object
+ # Look for memcache entry first
+ rows = yield self._cacher.get(str(self._resourceID))
+ if rows is None:
+ rows = yield self._allWithID.on(txn, resourceID=self._resourceID)
+ yield self._cacher.set(str(self._resourceID),
+ rows if rows is not None else ())
+ for name, uid, value in rows:
+ self._cached[(name, uid)] = value
+
+
@classmethod
@inlineCallbacks
def load(cls, defaultuser, txn, resourceID, created=False):
@@ -64,16 +81,7 @@
self._resourceID = resourceID
self._cached = {}
if not created:
- # Cache existing properties in this object
- # Look for memcache entry first
- rows = yield self._cacher.get(str(self._resourceID))
- if rows is None:
- rows = yield self._allWithID.on(txn,
- resourceID=self._resourceID)
- yield self._cacher.set(str(self._resourceID),
- rows if rows is not None else ())
- for name, uid, value in rows:
- self._cached[(name, uid)] = value
+ yield self._refresh(txn)
returnValue(self)
@@ -170,16 +178,29 @@
key_str = key.toString()
value_str = value.toxml()
- if (key_str, uid) in self._cached:
- self._updateQuery.on(self._txn, resourceID=self._resourceID,
- value=value_str, name=key_str, uid=uid)
- else:
- self._insertQuery.on(self._txn, resourceID=self._resourceID,
- value=value_str, name=key_str, uid=uid)
+ tried = []
+
+ wasCached = [(key_str, uid) in self._cached]
self._cached[(key_str, uid)] = value_str
- self._cacher.delete(str(self._resourceID))
+ @inlineCallbacks
+ def trySetItem(txn):
+ if tried:
+ yield self._refresh(txn)
+ wasCached[:] = [(key_str, uid) in self._cached]
+ tried.append(True)
+ if wasCached[0]:
+ yield self._updateQuery.on(
+ txn, resourceID=self._resourceID, value=value_str,
+ name=key_str, uid=uid)
+ else:
+ yield self._insertQuery.on(
+ txn, resourceID=self._resourceID, value=value_str,
+ name=key_str, uid=uid)
+ self._cacher.delete(str(self._resourceID))
+ self._txn.subtransaction(trySetItem)
+
_deleteQuery = Delete(
prop, Where=(prop.RESOURCE_ID == Parameter("resourceID")).And(
prop.NAME == Parameter("name")).And(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110324/4bc6159d/attachment.html>
More information about the calendarserver-changes
mailing list