[CalendarServer-changes] [6983] CalendarServer/branches/users/glyph/dalify/txdav/base/propertystore/ sql.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 16 06:35:49 PST 2011
Revision: 6983
http://trac.macosforge.org/projects/calendarserver/changeset/6983
Author: glyph at apple.com
Date: 2011-02-16 06:35:49 -0800 (Wed, 16 Feb 2011)
Log Message:
-----------
dalify PropertyStore.load
Modified Paths:
--------------
CalendarServer/branches/users/glyph/dalify/txdav/base/propertystore/sql.py
Modified: CalendarServer/branches/users/glyph/dalify/txdav/base/propertystore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/dalify/txdav/base/propertystore/sql.py 2011-02-16 14:35:38 UTC (rev 6982)
+++ CalendarServer/branches/users/glyph/dalify/txdav/base/propertystore/sql.py 2011-02-16 14:35:49 UTC (rev 6983)
@@ -25,6 +25,11 @@
from twistedcaldav.memcacher import Memcacher
+from twext.enterprise.dal.syntax import Select
+from twext.enterprise.dal.syntax import Parameter
+
+from txdav.common.datastore.sql_tables import schema
+
from txdav.base.propertystore.base import AbstractPropertyStore, PropertyName,\
validKey
@@ -32,6 +37,9 @@
from twisted.internet.defer import inlineCallbacks, returnValue
+
+prop = schema.RESOURCE_PROPERTY
+
class PropertyStore(AbstractPropertyStore):
_cacher = Memcacher("propertystore.sql", pickle=True, key_normalization=False)
@@ -42,6 +50,11 @@
)
+ _allWithID = Select([prop.NAME, prop.VIEWER_UID, prop.VALUE],
+ From=prop,
+ Where=prop.RESOURCE_ID == Parameter("resourceID"))
+
+
@classmethod
@inlineCallbacks
def load(cls, defaultuser, txn, resourceID, created=False):
@@ -51,27 +64,19 @@
self._resourceID = resourceID
self._cached = {}
if not created:
-
- # Cache existing properties in this object
-
+ # 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._txn.execSQL(
- """
- select NAME, VIEWER_UID, VALUE from RESOURCE_PROPERTY
- where RESOURCE_ID = %s
- """,
- [self._resourceID]
- )
- yield self._cacher.set(str(self._resourceID), rows if rows is not None else ())
+ 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
+ returnValue(self)
- returnValue(self)
-
@classmethod
@inlineCallbacks
def loadAll(cls, defaultuser, txn, joinTable, joinColumn, parentIDColumn, parentID):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/89720d20/attachment.html>
More information about the calendarserver-changes
mailing list