[CalendarServer-changes] [6104] CalendarServer/trunk/txcaldav/calendarstore/postgres.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 18 10:01:33 PDT 2010


Revision: 6104
          http://trac.macosforge.org/projects/calendarserver/changeset/6104
Author:   cdaboo at apple.com
Date:     2010-08-18 10:01:32 -0700 (Wed, 18 Aug 2010)
Log Message:
-----------
Fix some more query related issues. Make sure lookup by UID is restricted to calendar.

Modified Paths:
--------------
    CalendarServer/trunk/txcaldav/calendarstore/postgres.py

Modified: CalendarServer/trunk/txcaldav/calendarstore/postgres.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/postgres.py	2010-08-18 14:27:47 UTC (rev 6103)
+++ CalendarServer/trunk/txcaldav/calendarstore/postgres.py	2010-08-18 17:01:32 UTC (rev 6104)
@@ -67,7 +67,7 @@
 from twext.web2.http_headers import MimeType, generateContentType
 from twext.web2.dav.element.parser import WebDAVDocument
 
-from twext.python.log import Logger
+from twext.python.log import Logger, LoggingMixIn
 from twext.python.vcomponent import VComponent
 
 from twistedcaldav.customxml import NotificationType
@@ -133,9 +133,16 @@
     "BUSY-UNAVAILABLE": 3,
     "BUSY-TENTATIVE"  : 4,
 }
-indexfbtype_to_icalfbtype = dict([(v, k) for k,v in icalfbtype_to_indexfbtype.iteritems()])
 
+indexfbtype_to_icalfbtype = {
+    0: '?',
+    1: 'F',
+    2: 'B',
+    3: 'U',
+    4: 'T',
+}
 
+
 def _getarg(argname, argspec, args, kw):
     """
     Get an argument from some arguments.
@@ -1040,7 +1047,7 @@
         return "%%%s%%" % (arg,)
 
 
-class PostgresLegacyIndexEmulator(object):
+class PostgresLegacyIndexEmulator(LoggingMixIn):
     """
     Emulator for L{twistedcaldv.index.Index} and
     L{twistedcaldv.index.IndexSchedule}.
@@ -1089,13 +1096,21 @@
         Gives all resources which have not been expanded beyond a given date
         in the database.  (Unused; see above L{postgresqlgenerator}.
         """
-        return self._txn.execSQL(
+        return [row[0] for row in self._txn.execSQL(
             "select RESOURCE_NAME from CALENDAR_OBJECT "
             "where RECURRANCE_MAX < %s and CALENDAR_RESOURCE_ID = %s",
             [normalizeForIndex(minDate), self.calendar._resourceID]
-        )
+        )]
 
 
+    def reExpandResource(self, name, expand_until):
+        """
+        Given a resource name, remove it from the database and re-add it
+        with a longer expansion.
+        """
+        obj = self.calendar.calendarObjectWithName(name)
+        obj.updateDatabase(obj.component(), expand_until=expand_until, reCreate=True)
+
     def testAndUpdateIndex(self, minDate):
         # Find out if the index is expanded far enough
         names = self.notExpandedBeyond(minDate)
@@ -1165,8 +1180,9 @@
         for row in rowiter:
             if fbtype:
                 row = list(row)
-                if row[9]:
-                    row[8] = row[9]
+                row[4] = 'Y' if row[4] else 'N'
+                row[7] = indexfbtype_to_icalfbtype[row[7]]
+                row[8] = 'T' if row[9] else 'F'
                 del row[9]
             yield row
 
@@ -1276,16 +1292,18 @@
         return PostgresCalendarObject(self, name, resid)
 
 
+    @memoized('uid', '_objects')
     def calendarObjectWithUID(self, uid):
         rows = self._txn.execSQL(
-            "select RESOURCE_NAME from CALENDAR_OBJECT where "
-            "ICALENDAR_UID = %s",
-            [uid]
+            "select RESOURCE_ID, RESOURCE_NAME from CALENDAR_OBJECT where "
+            "ICALENDAR_UID = %s and CALENDAR_RESOURCE_ID = %s",
+            [uid, self._resourceID]
         )
         if not rows:
             return None
-        name = rows[0][0]
-        return self.calendarObjectWithName(name)
+        resid = rows[0][0]
+        name = rows[0][1]
+        return PostgresCalendarObject(self, name, resid)
 
 
     def createCalendarObjectWithName(self, name, component):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100818/480ef524/attachment-0001.html>


More information about the calendarserver-changes mailing list