[CalendarServer-changes] [10934] CalendarServer/branches/users/gaya/sharedgroups
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 15 12:43:37 PDT 2013
Revision: 10934
http://trac.calendarserver.org//changeset/10934
Author: gaya at apple.com
Date: 2013-03-15 12:43:37 -0700 (Fri, 15 Mar 2013)
Log Message:
-----------
use only one instance of homeChild object during sharing
Modified Paths:
--------------
CalendarServer/branches/users/gaya/sharedgroups/testserver
CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/sql.py
Modified: CalendarServer/branches/users/gaya/sharedgroups/testserver
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/testserver 2013-03-15 19:39:51 UTC (rev 10933)
+++ CalendarServer/branches/users/gaya/sharedgroups/testserver 2013-03-15 19:43:37 UTC (rev 10934)
@@ -49,7 +49,7 @@
'?') usage; ;;
'h') usage -; exit 0; ;;
't') cdt="${OPTARG}"; serverinfo="${OPTARG}/scripts/server/serverinfo.xml"; ;;
- 'd') subdir="${OPTARG}"; ;;
+ 'd') subdir="--subdir ${OPTARG} "; ;;
's') serverinfo="${OPTARG}"; ;;
'r') printres="--always-print-request --always-print-response"; ;;
'v') verbose="v"; ;;
@@ -68,5 +68,5 @@
source "${wd}/support/shell.sh";
-cd "${cdt}" && "${python}" testcaldav.py --print-details-onfail ${printres} -s "${serverinfo}" --subdir "${subdir}" "$@";
+cd "${cdt}" && "${python}" testcaldav.py --print-details-onfail ${printres} -s "${serverinfo}" "${subdir}""$@";
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py 2013-03-15 19:39:51 UTC (rev 10933)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py 2013-03-15 19:43:37 UTC (rev 10934)
@@ -772,40 +772,44 @@
bindRows = yield cls._bindForNameAndHomeID.on(home._txn, name=name, homeID=home._resourceID)
if bindRows:
bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = bindRows[0] #@UnusedVariable
- if (bindStatus == _BIND_STATUS_ACCEPTED) == bool(accepted):
- # alt:
- # returnValue((yield cls.objectWithID(home, resourceID)))
- ownerHome = yield home.ownerHomeWithChildID(resourceID)
- if accepted:
- returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
- else:
- returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
+ if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
+ returnValue(None)
+ # alt:
+ # returnValue((yield cls.objectWithID(home, resourceID)))
+ ownerHome = yield home.ownerHomeWithChildID(resourceID)
+ if accepted:
+ returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
+ else:
+ returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
+
groupBindRows = yield AddressBookObject._bindForNameAndHomeID.on(
home._txn, name=name, homeID=home._resourceID
)
if groupBindRows:
bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = groupBindRows[0] #@UnusedVariable
- if (bindStatus == _BIND_STATUS_ACCEPTED) == bool(accepted):
- ownerAddressBookID = yield AddressBookObject.ownerAddressBookFromGroupID(home._txn, resourceID)
- # alt:
- # addressbook = yield cls.objectWithID(home, ownerAddressBookID)
- ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
- addressbook = yield home.childWithName(ownerHome.shareeAddressBookName())
- if not addressbook:
- addressbook = yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)
+ if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
+ returnValue(None)
- if accepted:
- returnValue((yield addressbook.objectResourceWithID(resourceID)))
- else:
- returnValue((yield AddressBookObject.objectWithID(addressbook, resourceID))) # avoids object cache
+ ownerAddressBookID = yield AddressBookObject.ownerAddressBookFromGroupID(home._txn, resourceID)
+ # alt:
+ # addressbook = yield cls.objectWithID(home, ownerAddressBookID)
+ ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
+ addressbook = yield home.childWithName(ownerHome.shareeAddressBookName())
+ if not addressbook:
+ addressbook = yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)
+ if accepted:
+ returnValue((yield addressbook.objectResourceWithID(resourceID)))
+ else:
+ returnValue((yield AddressBookObject.objectWithID(addressbook, resourceID))) # avoids object cache
+
returnValue(None)
@classmethod
@inlineCallbacks
- def objectWithID(cls, home, resourceID):
+ def objectWithID(cls, home, resourceID, accepted=True):
"""
Retrieve the child with the given C{resourceID} contained in the given
C{home}.
@@ -823,26 +827,31 @@
)
if bindRows:
bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = bindRows[0] #@UnusedVariable
+ if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
+ returnValue(None)
+
ownerHome = yield home.ownerHomeWithChildID(resourceID)
- if bindStatus == _BIND_STATUS_ACCEPTED:
+ if accepted:
returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
else:
returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
- result = None
groupBindRows = yield AddressBookObject._bindWithHomeIDAndAddressBookID.on(
home._txn, homeID=home._resourceID, addressbookID=resourceID
)
if groupBindRows:
bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = groupBindRows[0] #@UnusedVariable
+ if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
+ returnValue(None)
+
ownerAddressBookID = yield AddressBookObject.ownerAddressBookFromGroupID(home._txn, resourceID)
ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
- result = yield home.childWithName(ownerHome.shareeAddressBookName())
- if not result:
- result = yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)
- assert result
+ if accepted:
+ returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
+ else:
+ returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
- returnValue(result)
+ returnValue(None)
def shareUID(self):
@@ -1085,10 +1094,13 @@
if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
if 0 == previouslyAcceptedBindCount:
yield shareeView._initSyncToken()
+ shareeView._home._children[shareeView._name] = shareeView
+ shareeView._home._children[shareeView._resourceID] = shareeView
elif shareeView._bindStatus == _BIND_STATUS_DECLINED:
if 1 == previouslyAcceptedBindCount:
shareeView._deletedSyncToken(sharedRemoval=True)
shareeView._home._children.pop(shareeView._name, None)
+ shareeView._home._children.pop(shareeView._resourceID, None)
if message is not None:
@@ -1128,17 +1140,9 @@
)
result = []
- cls = self._home._childClass # for ease of grepping...
for bindMode, homeID, resourceID, bindName, bindStatus, bindMessage in bindRows: #@UnusedVariable
home = yield self._txn.homeWithResourceID(self._home._homeType, homeID)
- new = cls(
- home=home,
- name=self.shareeAddressBookName(), resourceID=self._resourceID,
- mode=bindMode, status=bindStatus,
- message=bindMessage, ownerHome=self._home,
- bindName=bindName
- )
- yield new.initFromStore()
+ new = yield home.childWithName(self.shareeAddressBookName())
result.append(new)
returnValue(result)
@@ -1164,17 +1168,9 @@
bindRows = yield self._unacceptedBindForResourceID.on(
self._txn, resourceID=self._resourceID
)
- cls = self._home._childClass # for ease of grepping...
for bindMode, homeID, resourceID, bindName, bindStatus, bindMessage in bindRows: #@UnusedVariable
home = yield self._txn.homeWithResourceID(self._home._homeType, homeID)
- new = cls(
- home=home,
- name=self.shareeAddressBookName(), resourceID=self._resourceID,
- mode=bindMode, status=bindStatus,
- message=bindMessage, ownerHome=self._home,
- bindName=bindName
- )
- yield new.initFromStore()
+ new = yield self.objectWithName(home, self.shareeAddressBookName(), accepted=False)
result.append(new)
returnValue(result)
@@ -1202,7 +1198,8 @@
)))
if acceptedBindCount == 1:
sharedAddressBook._deletedSyncToken(sharedRemoval=True)
- shareeHome._children.pop(self.shareeAddressBookName(), None)
+ shareeHome._children.pop(self.sharedAddressBook.name(), None)
+ shareeHome._children.pop(self.sharedAddressBook._resourceID, None)
elif not sharedAddressBook.fullyShared():
#FIXME: remove objects for this group only using self.removeObjectResource
self._objectNames = None
@@ -2085,6 +2082,7 @@
if acceptedBindCount == 1:
sharedAddressBook._deletedSyncToken(sharedRemoval=True)
shareeHome._children.pop(self._addressbook.shareeAddressBookName(), None)
+ shareeHome._children.pop(self._addressbook._resourceID, None)
# Must send notification to ensure cache invalidation occurs
yield self.notifyChanged()
@@ -2172,10 +2170,13 @@
if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
if 0 == previouslyAcceptedBindCount:
yield shareeView._addressbook._initSyncToken()
+ shareeView._home._children[shareeView._addressbook._name] = shareeView._addressbook
+ shareeView._home._children[shareeView._addressbook._resourceID] = shareeView._addressbook
elif shareeView._bindStatus != _BIND_STATUS_INVITED:
if 1 == previouslyAcceptedBindCount:
shareeView._addressbook._deletedSyncToken(sharedRemoval=True)
shareeView._home._children.pop(shareeView._addressbook._name, None)
+ shareeView._home._children.pop(shareeView._addressbook._resourceID, None)
if message is not None:
shareeView._bindMessage = columnMap[bind.MESSAGE]
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/sql.py 2013-03-15 19:39:51 UTC (rev 10933)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/sql.py 2013-03-15 19:43:37 UTC (rev 10934)
@@ -1684,8 +1684,10 @@
if child is None:
raise NoSuchHomeChildError()
+ resourceID = child._resourceID
yield child.remove()
self._children.pop(name, None)
+ self._children.pop(resourceID, None)
@classproperty
@@ -2566,29 +2568,24 @@
if status is None:
status = _BIND_STATUS_ACCEPTED
- @inlineCallbacks
- def doInsert(subt):
- newName = str(uuid4())
+ child = yield shareeHome.childWithID(self._resourceID)
+ if child:
+ bindName = yield self.updateShare(
+ child, mode=mode, status=status,
+ message=message
+ )
+ else:
+ bindName = str(uuid4())
yield self._bindInsertQuery.on(
- subt, homeID=shareeHome._resourceID,
- resourceID=self._resourceID, name=newName,
+ self._txn, homeID=shareeHome._resourceID,
+ resourceID=self._resourceID, name=bindName,
mode=mode, bindStatus=status, message=message
)
- returnValue(newName)
- try:
- sharedName = yield self._txn.subtransaction(doInsert)
- except AllRetriesFailed:
- # FIXME: catch more specific exception
- sharedName = (yield self._updateBindQuery.on(
- self._txn,
- mode=mode, status=status, message=message,
- resourceID=self._resourceID, homeID=shareeHome._resourceID
- ))[0][0]
# Must send notification to ensure cache invalidation occurs
yield self.notifyChanged()
- returnValue(sharedName)
+ returnValue(bindName)
@classmethod
@@ -2655,9 +2652,12 @@
shareeView._bindStatus = columnMap[bind.BIND_STATUS]
if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
yield shareeView._initSyncToken()
+ shareeView._home._children[shareeView._name] = shareeView
+ shareeView._home._children[shareeView._resourceID] = shareeView
elif shareeView._bindStatus == _BIND_STATUS_DECLINED:
shareeView._deletedSyncToken(sharedRemoval=True)
shareeView._home._children.pop(shareeView._name, None)
+ shareeView._home._children.pop(shareeView._resourceID, None)
if message is not None:
shareeView._bindMessage = columnMap[bind.MESSAGE]
@@ -2705,6 +2705,7 @@
if not shareeChild.owned() and shareeChild._resourceID == self._resourceID:
shareeChild._deletedSyncToken(sharedRemoval=True)
shareeHome._children.pop(shareeChild._name, None)
+ shareeHome._children.pop(shareeChild._resourceID, None)
# Must send notification to ensure cache invalidation occurs
yield self.notifyChanged()
@@ -2761,17 +2762,11 @@
self._txn, resourceID=self._resourceID,
)
- cls = self._home._childClass # for ease of grepping...
result = []
- for bindMode, homeID, resourceID, resourceName, bindStatus, bindMessage in acceptedRows: #@UnusedVariable
- # TODO: this could all be issued in parallel; no need to serialize
- # the loop.
- new = cls(
- home=(yield self._txn.homeWithResourceID(self._home._homeType, homeID)),
- name=resourceName, resourceID=self._resourceID,
- mode=bindMode, status=bindStatus,
- message=bindMessage, ownerHome=self._home
- )
+ for bindMode, homeID, resourceID, bindName, bindStatus, bindMessage in acceptedRows: #@UnusedVariable
+ home = yield self._txn.homeWithResourceID(self._home._homeType, homeID)
+ new = yield home.objectWithShareUID(bindName)
+
yield new.initFromStore()
result.append(new)
returnValue(result)
@@ -2795,19 +2790,11 @@
rows = yield self._unacceptedBindForResourceID.on(
self._txn, resourceID=self._resourceID,
)
- cls = self._home._childClass # for ease of grepping...
result = []
- for bindMode, homeID, resourceID, resourceName, bindStatus, bindMessage in rows: #@UnusedVariable
- # TODO: this could all be issued in parallel; no need to serialize
- # the loop.
- new = cls(
- home=(yield self._txn.homeWithResourceID(self._home._homeType, homeID)),
- name=resourceName, resourceID=self._resourceID,
- mode=bindMode, status=bindStatus,
- message=bindMessage, ownerHome=self._home
- )
- yield new.initFromStore()
+ for bindMode, homeID, resourceID, bindName, bindStatus, bindMessage in rows: #@UnusedVariable
+ home = yield self._txn.homeWithResourceID(self._home._homeType, homeID)
+ new = yield home.invitedObjectWithShareUID(bindName)
result.append(new)
returnValue(result)
@@ -2999,7 +2986,7 @@
# Create the actual objects merging in properties
for items in dataRows:
- bindMode, homeID, resourceID, resourceName, bindStatus, bindMessage = items[:6] #@UnusedVariable
+ bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = items[:6] #@UnusedVariable
metadata = items[6:]
if bindStatus == _BIND_MODE_OWN:
@@ -3010,7 +2997,7 @@
child = cls(
home=home,
- name=resourceName, resourceID=resourceID,
+ name=bindName, resourceID=resourceID,
mode=bindMode, status=bindStatus,
message=bindMessage, ownerHome=ownerHome
)
@@ -3062,7 +3049,7 @@
if not rows:
returnValue(None)
- bindMode, homeID, resourceID, resourceName, bindStatus, bindMessage = rows[0] #@UnusedVariable
+ bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = rows[0] #@UnusedVariable
if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
returnValue(None)
@@ -3083,7 +3070,7 @@
@classmethod
@inlineCallbacks
- def objectWithID(cls, home, resourceID):
+ def objectWithID(cls, home, resourceID, accepted=True):
"""
Retrieve the child with the given C{resourceID} contained in the given
C{home}.
@@ -3098,22 +3085,11 @@
if not rows:
returnValue(None)
- bindMode, homeID, resourceID, resourceName, bindStatus, bindMessage = rows[0] #@UnusedVariable
-
- if bindMode == _BIND_MODE_OWN:
- ownerHome = home
+ bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = rows[0] #@UnusedVariable
+ if accepted:
+ returnValue((yield home.objectWithShareUID(bindName)))
else:
- ownerHomeID = (yield cls._ownerHomeWithResourceID.on(
- home._txn, resourceID=resourceID))[0][0]
- ownerHome = yield home._txn.homeWithResourceID(home._homeType, ownerHomeID)
- child = cls(
- home=home,
- name=resourceName, resourceID=resourceID,
- mode=bindMode, status=bindStatus,
- message=bindMessage, ownerHome=ownerHome,
- )
- yield child.initFromStore()
- returnValue(child)
+ returnValue((yield home.invitedObjectWithShareUID(bindName)))
@classproperty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130315/c09d97c6/attachment-0001.html>
More information about the calendarserver-changes
mailing list