Changeset 080097 in indico


Ignore:
Timestamp:
07/15/11 11:53:05 (23 months ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, burotel, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
Children:
bedc940
Parents:
3fb24b
git-author:
Pedro Ferreira <jose.pedro.ferreira@…> (07/13/11 14:22:15)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (07/15/11 11:53:05)
Message:

[IMP] Category list Optimization - first step

  • Using iterators instead of list conversion;
Location:
indico
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • indico/MaKaC/common/indexes.py

    r8b23c0 r080097  
    980980    pass 
    981981 
    982 class DoubleIndex(Index): 
    983  
    984     def __init__( self, name='' ): 
    985         if name != '': 
    986             self._name = name 
    987         self._words = OOBTree() 
    988         self._ids = OOBTree() 
    989  
    990     def _addItem( self, value, item ): 
    991         if value != "": 
    992             words = self._words 
    993             if words.has_key(value): 
    994                 if item not in words[value]: 
    995                     l = words[value] 
    996                     l.append(item) 
    997                     words[value] = l 
    998             else: 
    999                 words[value] = [ item ] 
    1000             self.setIndex(words) 
    1001             id = self._itemToId(item) 
    1002             if self._ids.has_key(value): 
    1003                 if id not in self._ids[value]: 
    1004                     l = self._ids[value] 
    1005                     l.append(id) 
    1006                     self._ids[value] = l 
    1007             else: 
    1008                 self._ids[value] = [id] 
    1009             self._p_changed = 1 
    1010  
    1011     def _withdrawItem( self, value, item ): 
    1012         if self._words.has_key(value): 
    1013             if item in self._words[value]: 
    1014                 words = self._words 
    1015                 l = words[value] 
    1016                 l.remove(item) 
    1017                 words[value] = l 
    1018                 self.setIndex(words) 
    1019         id = self._itemToId(item) 
    1020         if self._ids.has_key(value): 
    1021             if id in self._ids[value]: 
    1022                 l = self._ids[value] 
    1023                 l.remove(id) 
    1024                 self._ids[value] = l 
    1025         self._p_changed = 1 
    1026  
    1027     def _itemToId(self, item): 
    1028         #to be overloaded 
    1029         return "" 
    1030  
    1031     def initIndex(self): 
    1032         self._words = OOBTree() 
    1033         self._ids = OOBTree() 
    1034         self._p_changed = 1 
    1035  
    1036     def getLowerIndex(self): 
    1037         if self._words.keys(): 
    1038             return min(self._words.keys()) 
    1039         return None 
    1040  
    1041 class OAIDoubleIndex(DoubleIndex): 
    1042  
    1043     def __init__(self, name='' ): 
    1044         DoubleIndex.__init__(self, name) 
    1045         self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 ) 
    1046  
    1047     def initIndex( self ): 
    1048         DoubleIndex.initIndex(self) 
    1049         self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 ) 
    1050  
    1051     def getElements(self, from_date, until_date): 
    1052         if not (from_date or until_date): 
    1053             return self.getAllElements() 
    1054  
    1055         if from_date: 
    1056             fd = datetime(int(from_date[0:4]), int(from_date[5:7]), int(from_date[8:10]), tzinfo=timezone('UTC')) 
    1057         else: 
    1058             fd = self.firstDate 
    1059  
    1060         if until_date: 
    1061             ud = datetime(int(until_date[0:4]), int(until_date[5:7]), int(until_date[8:10]), tzinfo=timezone('UTC')) 
    1062         else: 
    1063             ud = nowutc().replace( hour=23, minute=59, second=59, microsecond=0 ) 
    1064  
    1065         res = [] 
    1066         if fd > ud: 
    1067             return res 
    1068         delta = timedelta(1) 
    1069         while fd <= ud: 
    1070             d = fd.strftime("%Y-%m-%d") 
    1071             if d in self._words: 
    1072                 res.extend(self._words[d]) 
    1073             fd += delta 
    1074         return res 
    1075  
    1076  
    1077     def getElementIds(self, from_date, until_date): 
    1078         if not (from_date or until_date): 
    1079             return self.getAllElementIds() 
    1080  
    1081         if from_date: 
    1082             fd = datetime(int(from_date[0:4]), int(from_date[5:7]), int(from_date[8:10]), tzinfo=timezone('UTC')) 
    1083         else: 
    1084             fd = self.firstDate 
    1085  
    1086         if until_date: 
    1087             ud = datetime(int(until_date[0:4]), int(until_date[5:7]), int(until_date[8:10]), tzinfo=timezone('UTC')) 
    1088         else: 
    1089             ud = nowutc().replace( hour=23, minute=59, second=59, microsecond=0 ) 
    1090  
    1091         res = [] 
    1092         if fd > ud: 
    1093             return res 
    1094  
    1095         delta = timedelta(1) 
    1096         while fd <= ud: 
    1097             d = fd.strftime("%Y-%m-%d") 
    1098             if d in self._ids: 
    1099                 res.extend(self._ids[d]) 
    1100             fd += delta 
    1101         return res 
    1102  
    1103     def getAllElements(self): 
    1104         res = [] 
    1105         for date in self._words.keys(): 
    1106             res.extend(self._words[date]) 
    1107         return res 
    1108  
    1109     def getAllElementIds(self): 
    1110         res = [] 
    1111         for date in self._ids.keys(): 
    1112             res.extend(self._ids[date]) 
    1113         return res 
    1114  
    1115     def unindexElement( self, cont ): 
    1116         date = cont.getOAIModificationDate().strftime("%Y-%m-%d") 
    1117         self._withdrawItem( date, cont ) 
    1118  
    1119  
    1120 class OAIContributionIndex( OAIDoubleIndex ): 
    1121     def __init__(self, name='' ): 
    1122         OAIDoubleIndex.__init__(self, name) 
    1123         self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 ) 
    1124  
    1125     def initIndex( self ): 
    1126         OAIDoubleIndex.initIndex(self) 
    1127         self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 ) 
    1128  
    1129     def _itemToId(self, item): 
    1130         from MaKaC.conference import Contribution, SubContribution 
    1131         if isinstance(item, Contribution): 
    1132             return "%s:%s"%(item.getConference().getId(), item.getId()) 
    1133         elif isinstance(item, SubContribution): 
    1134             return "%s:%s:%s"%(item.getConference().getId(), item.getContribution().getId(), item.getId()) 
    1135         return "" 
    1136  
    1137     def getContributions(self, from_date, until_date): 
    1138         return OAIDoubleIndex.getElements(self, from_date, until_date) 
    1139  
    1140     def getContributionsIds(self, from_date, until_date): 
    1141         return OAIDoubleIndex.getElementIds(self, from_date, until_date) 
    1142  
    1143     def getAllContributions(self): 
    1144         return OAIDoubleIndex.getAllElements(self) 
    1145  
    1146     def getAllContributionsIds(self): 
    1147         return OAIDoubleIndex.getAllElementIds(self) 
    1148  
    1149     def unindexContribution( self, cont ): 
    1150         return OAIDoubleIndex.unindexElement(self, cont) 
    1151  
    1152     def indexContribution( self, cont ): 
    1153 #        Logger.get('oai/indexes').debug("\tINDEXING %s from conf %s" % (cont.getId(), cont.getConference().getId())) 
    1154         if not self.isIndexable(cont): 
    1155 #            Logger.get('oai/indexes').debug("\t\tUNINDEXED - contribution is not indexable") 
    1156             self.unindexContribution(cont) 
    1157             return 
    1158         from MaKaC.conference import ContribStatusWithdrawn 
    1159         if not isinstance(cont.getContribution().getCurrentStatus(), ContribStatusWithdrawn): 
    1160             date = cont.getOAIModificationDate() 
    1161             strDate = date.strftime("%Y-%m-%d") 
    1162             if date < self.firstDate: 
    1163                 self.firstDate = date 
    1164             self._addItem( strDate, cont ) 
    1165  
    1166 class OAIContributionModificationDateIndex( OAIContributionIndex ): 
    1167     _name = "OAIContributionModificationDate" 
    1168  
    1169     def isIndexable(self, conf): 
    1170         # only public conferences shoud be indexed 
    1171         return not conf.hasAnyProtection() 
    1172  
    1173  
    1174 class OAIPrivateContributionModificationDateIndex( OAIContributionIndex ): 
    1175     _name = "OAIPrivateContributionModificationDate" 
    1176  
    1177     def __init__( self, name='' ): 
    1178         OAIContributionIndex.__init__(self, name) 
    1179  
    1180     def indexContribution( self, cont ): 
    1181         if not cont.hasAnyProtection(): 
    1182             self.unindexContribution(cont) 
    1183             return 
    1184         from MaKaC.conference import ContribStatusWithdrawn 
    1185         if not isinstance(cont.getContribution().getCurrentStatus(), ContribStatusWithdrawn): 
    1186             date = cont.getOAIModificationDate() 
    1187             strDate = date.strftime("%Y-%m-%d") 
    1188             if date < self.firstDate: 
    1189                 self.firstDate = date 
    1190             self._addItem( strDate, cont ) 
    1191  
    1192 class OAIDeletedContributionModificationDateIndex( OAIContributionModificationDateIndex ): 
    1193     _name = "OAIDeletedContributionModificationDate" 
    1194  
    1195     def indexContribution( self, cont ): 
    1196         date = cont.getOAIModificationDate() 
    1197         strDate = date.strftime("%Y-%m-%d") 
    1198         if date < self.firstDate: 
    1199             self.firstDate = date 
    1200         self._addItem( strDate, cont ) 
    1201  
    1202 class OAIDeletedPrivateContributionModificationDateIndex(OAIDeletedContributionModificationDateIndex): 
    1203     _name = "OAIDeletedPrivateContributionModificationDate" 
    1204  
    1205  
    1206 class OAIDeletedContributionCategoryIndex( OAIContributionIndex ): 
    1207     _name = "OAIDeletedContributionCategory" 
    1208  
    1209     def __init__( self, name='' ): 
    1210         OAIContributionIndex.__init__(self, name) 
    1211  
    1212     def _itemToId(self, item): 
    1213         return item.getId() 
    1214  
    1215     def indexContribution( self, cont ): 
    1216         for catId in cont.getCategoryPath(): 
    1217             self._addItem( catId, cont ) 
    1218  
    1219     def unindexContribution( self, cont ): 
    1220         for catId in cont.getCategoryPath(): 
    1221             self._withdrawItem( catId, cont ) 
    1222  
    1223     def getContributions(self, catId): 
    1224         if not catId in self._ids: 
    1225             return [] 
    1226         return self._words[catId] 
    1227  
    1228     def getContributionsIds(self, catId): 
    1229         if not catId in self._ids: 
    1230             return [] 
    1231         return self._ids[catId] 
    1232  
    1233     def getAllConferences(self): 
    1234         return self.getAllElements() 
    1235  
    1236     def getAllConferencesIds(self): 
    1237         return self.getAllElementIds() 
    1238  
    1239 class OAIDeletedPrivateContributionCategoryIndex( OAIDeletedContributionCategoryIndex ): 
    1240     _name = "OAIDeletedPrivateContributionCategory" 
    1241  
    1242  
    1243 class OAIConferenceIndex( OAIDoubleIndex ): 
    1244  
    1245     def __init__( self, name='' ): 
    1246         OAIDoubleIndex.__init__(self, name) 
    1247         self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 ) 
    1248  
    1249     def initIndex( self ): 
    1250         OAIDoubleIndex.initIndex(self) 
    1251         self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 ) 
    1252  
    1253     def _itemToId(self, item): 
    1254         return item.getId() 
    1255  
    1256     def unindexElement( self, conf ): 
    1257         date = conf.getOAIModificationDate().strftime("%Y-%m-%d") 
    1258         self._withdrawItem( date, conf ) 
    1259  
    1260     def unindexConference( self, conf ): 
    1261         self.unindexElement(conf) 
    1262  
    1263     def getConferences(self, from_date, until_date): 
    1264         return OAIDoubleIndex.getElements(self, from_date, until_date) 
    1265  
    1266     def getConferencesIds(self, from_date, until_date): 
    1267         if not (from_date or until_date): 
    1268             return self.getAllConferencesIds() 
    1269  
    1270         if from_date: 
    1271             fd = datetime(int(from_date[0:4]), int(from_date[5:7]), int(from_date[8:10]), tzinfo=timezone('UTC')) 
    1272         else: 
    1273             fd = self.firstDate 
    1274  
    1275         if until_date: 
    1276             ud = datetime(int(until_date[0:4]), int(until_date[5:7]), int(until_date[8:10]), tzinfo=timezone('UTC')) 
    1277         else: 
    1278             ud = nowutc().replace( hour=23, minute=59, second=29, microsecond=0 ) 
    1279  
    1280         res = [] 
    1281         if fd > ud: 
    1282             return res 
    1283  
    1284         delta = timedelta(1) 
    1285         while fd <= ud: 
    1286             d = fd.strftime("%Y-%m-%d") 
    1287             if d in self._ids: 
    1288                 res.extend(self._ids[d]) 
    1289             fd += delta 
    1290  
    1291         return res 
    1292  
    1293     def getAllConferences(self): 
    1294         return OAIDoubleIndex.getAllElements(self) 
    1295  
    1296     def getAllConferencesIds(self): 
    1297         return OAIDoubleIndex.getAllElementIds(self) 
    1298  
    1299  
    1300 class OAIConferenceModificationDateIndex( OAIConferenceIndex ): 
    1301     _name = "OAIConferenceModificationDate" 
    1302  
    1303     def __init__( self, name='' ): 
    1304         OAIConferenceIndex.__init__(self, name) 
    1305  
    1306     def indexConference( self, conf ): 
    1307  
    1308         if conf.hasAnyProtection(): 
    1309             self.unindexConference(conf) 
    1310             return 
    1311         date = conf.getOAIModificationDate() 
    1312         strDate = date.strftime("%Y-%m-%d") 
    1313         if date < self.firstDate: 
    1314             self.firstDate = date 
    1315         self._addItem( strDate, conf ) 
    1316  
    1317     def isIndexable(self, conf): 
    1318         # only public conferences shoud be indexed 
    1319         return not conf.hasAnyProtection() 
    1320  
    1321  
    1322 class OAIPrivateConferenceModificationDateIndex( OAIConferenceModificationDateIndex ): 
    1323     _name = "OAIPrivateConferenceModificationDate" 
    1324  
    1325     def __init__( self, name='' ): 
    1326         OAIConferenceIndex.__init__(self, name) 
    1327  
    1328     def indexConference( self, conf ): 
    1329         if not conf.hasAnyProtection(): 
    1330             self.unindexConference(conf) 
    1331             return 
    1332         date = conf.getOAIModificationDate() 
    1333         strDate = date.strftime("%Y-%m-%d") 
    1334         if date < self.firstDate: 
    1335             self.firstDate = date 
    1336         self._addItem( strDate, conf ) 
    1337  
    1338 class OAIDeletedConferenceModificationDateIndex( OAIConferenceModificationDateIndex ): 
    1339     _name = "OAIDeletedConferenceModificationDate" 
    1340  
    1341     def isIndexable(self, conf): 
    1342         # only public conferences shoud be indexed 
    1343         return not conf.hasAnyProtection() 
    1344  
    1345 class OAIDeletedPrivateConferenceModificationDateIndex( OAIPrivateConferenceModificationDateIndex ): 
    1346     _name = "OAIDeletedPrivateConferenceModificationDate" 
    1347  
    1348  
    1349 class OAIDeletedConferenceCategoryIndex( OAIConferenceIndex ): 
    1350     _name = "OAIDeletedConferenceCategory" 
    1351  
    1352     def __init__( self, name='' ): 
    1353         OAIConferenceIndex.__init__(self, name) 
    1354  
    1355     def indexConference( self, conf ): 
    1356         for catId in conf.getCategoryPath(): 
    1357             self._addItem( catId, conf ) 
    1358  
    1359     def unindexConference( self, conf ): 
    1360         for catId in conf.getCategoryPath(): 
    1361             self._withdrawItem( catId, conf ) 
    1362  
    1363     def getConferences(self, catId): 
    1364         if not catId in self._ids: 
    1365             return [] 
    1366         return self._words[catId] 
    1367  
    1368     def getConferencesIds(self, catId): 
    1369         if not catId in self._ids: 
    1370             return [] 
    1371         return self._ids[catId] 
    1372  
    1373  
    1374 class OAIDeletedPrivateConferenceCategoryIndex( OAIDeletedConferenceCategoryIndex ): 
    1375     _name = "OAIDeletedPrivateConferenceCategory" 
    1376  
    1377982 
    1378983class IndexException(Exception): 
    1379984    pass 
     985 
    1380986 
    1381987class IntStringMappedIndex(Persistent): 
     
    14681074        records = self._textIdx.apply(text.decode('utf8')).items() 
    14691075        return [(self.getString(record[0]), record[1]) for record in records] 
     1076 
    14701077 
    14711078class IndexesHolder( ObjectHolder ): 
     
    14791086                    "pendingSubmittersTasks", "pendingManagers", 
    14801087                    "pendingManagersTasks", "pendingCoordinators", 
    1481                     "pendingCoordinatorsTasks", "webcasts", "collaboration", 
    1482                     "OAIConferenceModificationDate", 
    1483                     "OAIContributionModificationDate", 
    1484                     "OAIPrivateConferenceModificationDate", 
    1485                     "OAIPrivateContributionModificationDate", 
    1486                     "OAIDeletedConferenceModificationDate", 
    1487                     "OAIDeletedContributionModificationDate", 
    1488                     "OAIDeletedConferenceCategory", 
    1489                     "OAIDeletedContributionCategory", 
    1490                     "OAIDeletedPrivateConferenceModificationDate", 
    1491                     "OAIDeletedPrivateContributionModificationDate", 
    1492                     "OAIDeletedPrivateConferenceCategory", 
    1493                     "OAIDeletedPrivateContributionCategory"] 
     1088                    "pendingCoordinatorsTasks", "webcasts", "collaboration"] 
    14941089 
    14951090    def getIndex( self, name ): 
     
    15461141                    raise MaKaCError(_("Tried to retrieve collaboration index, but Collaboration plugins are not present")) 
    15471142 
    1548             # OAI date indices 
    1549             elif id=="OAIConferenceModificationDate": 
    1550                 Idx[str(id)] = OAIConferenceModificationDateIndex() 
    1551             elif id=="OAIContributionModificationDate": 
    1552                 Idx[str(id)] = OAIContributionModificationDateIndex() 
    1553             elif id=="OAIPrivateConferenceModificationDate": 
    1554                 Idx[str(id)] = OAIPrivateConferenceModificationDateIndex() 
    1555             elif id=="OAIPrivateContributionModificationDate": 
    1556                 Idx[str(id)] = OAIPrivateContributionModificationDateIndex() 
    1557             elif id=="OAIDeletedConferenceModificationDate": 
    1558                 Idx[str(id)] = OAIDeletedConferenceModificationDateIndex() 
    1559             elif id=="OAIDeletedContributionModificationDate": 
    1560                 Idx[str(id)] = OAIDeletedContributionModificationDateIndex() 
    1561             elif id=="OAIDeletedPrivateConferenceModificationDate": 
    1562                 Idx[str(id)] = OAIDeletedPrivateConferenceModificationDateIndex() 
    1563             elif id=="OAIDeletedPrivateContributionModificationDate": 
    1564                 Idx[str(id)] = OAIDeletedPrivateContributionModificationDateIndex() 
    1565  
    1566  
    1567             # category indices 
    1568             elif id=="OAIDeletedConferenceCategory": 
    1569                 Idx[str(id)] = OAIDeletedConferenceCategoryIndex() 
    1570             elif id=="OAIDeletedContributionCategory": 
    1571                 Idx[str(id)] = OAIDeletedContributionCategoryIndex() 
    1572             elif id=="OAIDeletedPrivateConferenceCategory": 
    1573                 Idx[str(id)] = OAIDeletedPrivateConferenceCategoryIndex() 
    1574             elif id=="OAIDeletedPrivateContributionCategory": 
    1575                 Idx[str(id)] = OAIDeletedPrivateContributionCategoryIndex() 
    1576             else: 
    1577                 Idx[str(id)] = Index() 
    1578  
    15791143            return Idx[str(id)] 
    15801144 
  • indico/MaKaC/conference.py

    ra7cc00 r080097  
    5656 
    5757from persistent import Persistent 
    58 from BTrees.OOBTree import OOBTree, OOTreeSet 
     58from BTrees.OOBTree import OOBTree, OOTreeSet, OOSet 
    5959from BTrees.OIBTree import OIBTree,OISet,union 
    6060import MaKaC 
     
    9797from MaKaC.common.contextManager import ContextManager 
    9898from sets import Set 
     99import zope.interface 
    99100 
    100101from indico.modules.scheduler import Client, tasks 
     102from indico.util.date_time import utc_timestamp 
     103from indico.core.index import IIndexableByStartDateTime, IUniqueIdProvider, Catalog 
    101104 
    102105 
     
    106109    """ 
    107110 
     111    zope.interface.implements(IUniqueIdProvider, 
     112                              IIndexableByStartDateTime) 
     113 
    108114    def setModificationDate(self, date = None): 
    109115        """ 
     
    113119            date = nowutc() 
    114120        self._modificationDS = date 
     121 
     122    def __conform__(self, proto): 
     123 
     124        if proto == IIndexableByStartDateTime: 
     125            return utc_timestamp(self.getStartDate()) 
     126        else: 
     127            return None 
    115128 
    116129 
     
    11021115 
    11031116    def removeConference( self, conf, notify=True, delete = False ): 
    1104         if not (conf in self.getConferenceList()): 
     1117        if not (conf in self.conferences): 
    11051118            return 
    11061119 
     
    11261139        return res 
    11271140 
     1141    def iteritems(self, *args): 
     1142        return self.conferences.iteritems(*args) 
     1143 
     1144    def itervalues(self, *args): 
     1145        return self.conferences.itervalues(*args) 
     1146 
    11281147    def getConferenceList( self, sortType=1 ): 
    11291148        """returns the list of conferences included in the current category. 
     
    11351154            sortType=3--> Alphabetically - Reversed 
    11361155        """ 
     1156 
    11371157        res = sorted(self.conferences, cmp=Conference._cmpByDate) 
     1158 
    11381159        if sortType==2: 
    11391160            res.sort(Conference._cmpTitle) 
     
    11581179        return res 
    11591180 
    1160     def getPreviousEvent(self, conf): 
    1161         cl=self.getConferenceList() 
    1162         v=None 
    1163         try: 
    1164             i=cl.index(conf) 
    1165             if i>0: 
    1166                 v=cl[i-1] 
    1167         except ValueError, e: 
    1168             pass 
    1169         return v 
    1170  
    1171     def getNextEvent(self, conf): 
    1172         cl=self.getConferenceList() 
    1173         v=None 
    1174         try: 
    1175             i=cl.index(conf) 
    1176             if i<(len(cl)-1): 
    1177                 v=cl[i+1] 
    1178         except ValueError, e: 
    1179             pass 
    1180         return v 
    1181  
    1182     def getFirstEvent(self, conf=None): 
    1183         cl=self.getConferenceList() 
    1184         if len(cl)>0 and cl[0]!=conf: 
    1185             return cl[0] 
    1186         return None 
    1187  
    1188     def getLastEvent(self, conf=None): 
    1189         cl=self.getConferenceList() 
    1190         if len(cl)>0 and cl[-1]!=conf: 
    1191             return cl[-1] 
    1192         return None 
     1181    def getNeighborEvents(self, conf): 
     1182 
     1183        index = Catalog.getIdx('categ_conf_sd').getCategory(conf.getOwner().getId()) 
     1184        first, last = list(index[index.minKey()])[0], list(index[index.maxKey()])[-1] 
     1185 
     1186        categIter = index.itervalues() 
     1187 
     1188        prev = None 
     1189        for c in categIter: 
     1190            if c == conf: 
     1191                break 
     1192            prev = c 
     1193 
     1194        nextEvt = next(categIter, None) 
     1195 
     1196        return prev, nextEvt, first, last 
    11931197 
    11941198    def _setNumConferences(self): 
     
    11981202                self._incNumConfs(sc.getNumConferences()) 
    11991203        else: 
    1200             self._incNumConfs(len(self.getConferenceList())) 
     1204            self._incNumConfs(len(self.conferences)) 
    12011205 
    12021206    def getNumConferences( self ): 
     
    20752079    @staticmethod 
    20762080    def _cmpByDate(self, toCmp): 
    2077         if not isinstance(toCmp, Conference): 
    2078             return cmp(hash(self), hash(toCmp)) 
    20792081        res = cmp(self.getStartDate(), toCmp.getStartDate()) 
    20802082        if res != 0: 
     
    20842086 
    20852087    def __cmp__(self, toCmp): 
    2086         if not isinstance(toCmp, Conference): 
     2088        if isinstance(toCmp, Conference): 
     2089            return cmp(self.getId(), toCmp.getId()) 
     2090        else: 
    20872091            return cmp(hash(self), hash(toCmp)) 
    2088         return cmp(self.getId(), toCmp.getId()) 
    20892092 
    20902093    def __eq__(self, toCmp): 
     
    24322435        catDateIdx.indexConf(self) 
    24332436 
     2437        Catalog.getIdx('categ_conf_sd').index_obj(self) 
     2438 
    24342439    def unindexConf( self ): 
    24352440        calIdx = indexes.IndexesHolder().getIndex('calendar') 
     
    24372442        catDateIdx = indexes.IndexesHolder().getIndex('categoryDate') 
    24382443        catDateIdx.unindexConf(self) 
     2444 
     2445        Catalog.getIdx('categ_conf_sd').unindex_obj(self) 
    24392446 
    24402447    def __generateNewContribTypeId( self ): 
  • indico/MaKaC/services/implementation/category.py

    r4e5048 r080097  
    2424 
    2525import datetime 
     26from itertools import islice 
    2627from MaKaC.services.implementation.base import ProtectedModificationService, ParameterManager 
    2728from MaKaC.services.implementation.base import ProtectedDisplayService, ServiceBase 
     
    3334from MaKaC.common.fossilize import fossilize 
    3435from MaKaC.user import PrincipalHolder, Avatar, Group 
     36 
     37from indico.core.index import Catalog 
    3538 
    3639class CategoryBase(object): 
     
    147150 
    148151    def _getAnswer( self ): 
    149         pastEvents = list(self._target.getConferenceList())[0:self._lastIdx] 
     152        index = Catalog.getIdx('categ_conf_sd').getCategory(self._categ.getId()) 
     153        pastEvents = list(islice(index.itervalues(), self._lastIdx)) 
    150154        return WConferenceListEvents(pastEvents, self._aw).getHTML() 
    151155 
  • indico/MaKaC/statistics.py

    r07abe7 r080097  
    121121                stats["resources"] += scat._statistics["resources"] 
    122122 
    123         elif len(cat.getConferenceList()) > 0: 
    124             for event in cat.getConferenceList(): 
     123        elif cat.conferences: 
     124            for event in cat.conferences: 
    125125                cls._processEvent(dbi, event, stats) 
    126126 
  • indico/MaKaC/webinterface/pages/category.py

    r08a2885 r080097  
    3838from MaKaC.common.cache import CategoryCache 
    3939from MaKaC.i18n import _ 
     40 
    4041from MaKaC.webinterface.common.timezones import TimezoneRegistry 
    4142from MaKaC.webinterface.common.tools import escape_html 
     
    4344from pytz import timezone 
    4445from MaKaC.common.TemplateExec import truncateTitle 
     46 
     47from indico.util.i18n import i18nformat 
     48from indico.core.index import Catalog 
    4549 
    4650 
     
    135139        vars["img"] = self._target.getIconURL() 
    136140        vars["categ"] = self._target; 
    137         subcats = self._target.getSubCategoryList() 
    138         confs = self._target.getConferenceList() 
    139         if len(subcats) > 0: 
     141        subcats = self._target.subcategories 
     142 
     143        confs = self._target.conferences 
     144        if subcats: 
    140145            cl=wcomponents.WCategoryList( self._target ) 
    141146            params = {"categoryDisplayURLGen": vars["categDisplayURLGen"], "material": self._getMaterialHTML()} 
    142147            vars["contents"] = cl.getHTML( self._aw, params ) 
    143         elif len(confs) > 0: 
     148        elif confs: 
    144149            pastEvents = self._aw.getSession().getVar("fetchPastEventsFrom") 
    145150            showPastEvents = pastEvents and self._target.getId() in pastEvents or self._aw.getUser() and self._aw.getUser().getPersonalInfo().getShowPastEvents() 
     
    14891494    def getVars( self ): 
    14901495 
     1496        index = Catalog.getIdx('categ_conf_sd').getCategory(self._categ.getId()) 
    14911497        vars = wcomponents.WTemplated.getVars( self ) 
    14921498        vars["locator"] = self._categ.getLocator().getWebForm() 
     
    15061512            vars['containsEvents'] = True 
    15071513            vars["removeItemsURL"] = vars["actionConferencesURL"] 
    1508             vars["items"] = self.__getConferenceItems( reversed(self._categ.getConferenceList()), vars["confModifyURLGen"],  vars["confModifyURLOpen"]) 
     1514            vars["items"] = self.__getConferenceItems(index.itervalues(), vars["confModifyURLGen"],  vars["confModifyURLOpen"]) 
    15091515        else: 
    15101516            vars['containsEvents'] = False 
     
    20232029        if info.HelperMaKaCInfo.getMaKaCInfoInstance().isCacheActive(): 
    20242030            vars["clearCache"] = _("""<form action="%s" method="POST"><input type="submit" class="btn" value="_("clear category cache")"></form>""") % urlHandlers.UHCategoryClearCache.getURL(self._categ) 
    2025             if len(self._categ.getConferenceList()): 
     2031            if self._categ.conferences: 
    20262032                vars["clearCache"] += _("""<form action="%s" method="POST"><input type="submit" class="btn" value="_("clear conference caches")"></form>""") % urlHandlers.UHCategoryClearConferenceCaches.getURL(self._categ) 
    20272033        return vars 
  • indico/MaKaC/webinterface/tpls/CategoryDisplay.tpl

    r9ac2af7 r080097  
    1111            <li><a href="<%= urlHandlers.UHCategoryDisplay.getURL(categ.owner) %>"><%= _("Go to parent category") %></a>|</li> 
    1212        <% end %> 
    13             <% if categ.getConferenceList() != []: %> 
     13            <% if categ.conferences: %> 
    1414                <li><a href="<%= urlHandlers.UHCategoryToiCal.getURL(categ) %>"><%= _("iCal export")%></a>|</li> 
    1515            <% end %> 
  • indico/MaKaC/webinterface/tpls/EventHeader.tpl

    r9ac2af7 r080097  
    22owner = conf.getOwnerList()[0] 
    33 
    4 prev = owner.getPreviousEvent(conf) 
    5 next = owner.getNextEvent(conf) 
    6 first = owner.getFirstEvent(conf) 
    7 last = owner.getLastEvent(conf) 
     4prev, next, first, last = owner.getNeighborEvents(conf) 
    85 
    96# If printURL is set then show the print button 
  • indico/MaKaC/webinterface/wcomponents.py

    rc922b1 r080097  
    2222 
    2323import os,types,string 
     24import itertools 
    2425from xml.sax.saxutils import escape, quoteattr 
    2526from copy import copy 
     
    6566from MaKaC.common.contextManager import ContextManager 
    6667 
     68from indico.util.date_time import utc_timestamp 
     69from indico.core.index import Catalog 
     70 
    6771import re 
     72 
     73MIN_PRESENT_EVENTS = 6 
     74OPTIMAL_PRESENT_EVENTS = 10 
     75 
    6876 
    6977class WTemplated(OldObservable): 
     
    32803288    def __init__( self, category, wfRegm, showPastEvents ): 
    32813289        self._categ = category 
    3282         self._list = category.getConferenceList() 
    32833290        self._showPastEvents = showPastEvents 
    32843291 
     
    32873294        return WTemplated.getHTML( self, params ) 
    32883295 
    3289     def _findFirstEventFromCurrentMonth(self): 
    3290         currentDate = nowutc() 
    3291         return self._findEventIdx(datetime(currentDate.year, currentDate.month, 1, tzinfo=timezone('utc'))) 
    3292  
    3293     def _findPresentEvent(self): 
    3294         currentDate = nowutc() 
    3295         return self._findEventIdx(datetime(currentDate.year, currentDate.month, currentDate.day, tzinfo=timezone('utc'))) 
    3296  
    3297     def _findEventIdx(self, day): 
    3298         st = 0 
    3299         end = len(self._list) - 1 
    3300  
    3301         def find(st, end): 
    3302             current = int((st + end) / 2) 
    3303             if end - st > 1: 
    3304                 if self._list[current].getStartDate() > day: 
    3305                     return find(st, current) 
    3306                 elif self._list[current].getStartDate() < day: 
    3307                     return find(current, end) 
    3308                 else: 
    3309                     return current 
     3296    def getEventTimeline(self, tz): 
     3297        index = Catalog.getIdx('categ_conf_sd').getCategory(self._categ.getId()) 
     3298        today = nowutc().astimezone(timezone(tz)).replace(hour=0, minute=0, second=0) 
     3299        thisMonth = nowutc().astimezone(timezone(tz)).replace(hour=0, minute=0, second=0, day=1) 
     3300        thisMonthTS = utc_timestamp(thisMonth) 
     3301        todayTS = utc_timestamp(thisMonth) 
     3302        tomorrowTS = utc_timestamp(today + timedelta(days=1)) 
     3303        oneMonthTS = utc_timestamp(today - timedelta(days=30)) 
     3304        future = [] 
     3305        present = [] 
     3306 
     3307        for ts, conf in index.iteritems(thisMonthTS): 
     3308            if ts < tomorrowTS or len(present) < OPTIMAL_PRESENT_EVENTS: 
     3309                present.append(conf) 
    33103310            else: 
    3311                 if self._list[current].getStartDate() > day: 
    3312                     if current > 0: 
    3313                         return current - 1 
    3314                     else: 
    3315                         return 0 
    3316                 elif self._list[current].getStartDate() < day: 
    3317                     if current + 1< len(self._list): 
    3318                         return current + 1 
    3319                     else: 
    3320                         return current 
    3321                 else: 
    3322                     return current 
    3323  
    3324         return find(st, end) 
    3325  
    3326     def getPrevMonth(self,d): 
    3327         year = d.year 
    3328         prevMonth = (d.month - 1)%12 
    3329         if prevMonth == 0: 
    3330             prevMonth = 12 
    3331             year -= 1 
    3332         return datetime(year, prevMonth, 1, tzinfo = timezone('utc')) 
    3333  
    3334     def getNextMonth(self,d): 
    3335         year = d.year 
    3336         nextMonth = (d.month + 1)%12 
    3337         if d.month + 1 == 12: 
    3338             nextMonth = 12 
    3339         elif d.month + 1 > 12: 
    3340             year += 1 
    3341         return datetime(year, nextMonth, 1, tzinfo = timezone('utc')) 
    3342  
    3343     def _getEventsFromPreviousMonth(self, stIndex, previousMonthStart): 
    3344         newIndex = stIndex 
    3345         while newIndex >= 0 and self._list[newIndex].getStartDate() >= previousMonthStart: 
    3346             newIndex -= 1 
    3347         return newIndex if newIndex + 1 == len(self._list) else newIndex + 1 
    3348  
    3349     def _getEventsFromCurrentMonth(self, stIndex, currentMonthStart): 
    3350         nextMonthStart = self.getNextMonth(currentMonthStart) 
    3351         newIndex = stIndex 
    3352         while newIndex < len(self._list) and self._list[newIndex].getStartDate() < nextMonthStart: 
    3353             newIndex += 1 
    3354         return newIndex 
    3355  
    3356     def _getFutureEvents(self, stIndex): 
    3357         nextMonthStart = self.getNextMonth(self._list[stIndex + 1].getStartDate()) 
    3358         newIndex = stIndex 
    3359         while newIndex < len(self._list) and self._list[newIndex].getStartDate() < nextMonthStart: 
    3360             newIndex += 1 
    3361         return newIndex 
    3362  
    3363     def getPresentPastFutureEvents(self): 
    3364         currentMonth = nowutc() 
    3365         previousMonth = currentMonth 
    3366  
    3367         firstEventIdx = self._findFirstEventFromCurrentMonth() 
    3368         presentEventIdx = self._findPresentEvent() 
    3369         lastEventIdx = firstEventIdx 
    3370  
    3371         maxEventsShown = min([10, len(self._list)]) 
    3372         minFutureEventsShown = min([5, len(self._list) - presentEventIdx]) 
    3373  
    3374         lastEventIdx = self._getEventsFromCurrentMonth(lastEventIdx,currentMonth) 
    3375  
    3376         while lastEventIdx - firstEventIdx < maxEventsShown: 
    3377             currentMonth = self.getNextMonth(currentMonth) 
    3378             lastEventIdx = self._getEventsFromCurrentMonth(lastEventIdx,currentMonth) 
    3379             previousMonth = self.getPrevMonth(previousMonth) 
    3380             firstEventIdx = self._getEventsFromPreviousMonth(firstEventIdx,previousMonth) 
    3381  
    3382         while len(self._list) > lastEventIdx + 1 and lastEventIdx - presentEventIdx < minFutureEventsShown: 
    3383             lastEventIdx = self._getFutureEvents(lastEventIdx) 
    3384  
    3385         return list(self._list[firstEventIdx:lastEventIdx]), list(self._list[lastEventIdx:]),len(self._list) - lastEventIdx, firstEventIdx 
    3386  
    3387     def getVars( self ): 
    3388         vars = WTemplated.getVars( self ) 
    3389         vars["presentItems"], vars["futureItems"], vars["numOfEventsInTheFuture"], vars["numOfEventsInThePast"] =  self.getPresentPastFutureEvents() 
     3311                future.append(conf) 
     3312 
     3313        if len(present) < MIN_PRESENT_EVENTS: 
     3314            extraEvents = list(index.itervalues(oneMonthTS, todayTS)) 
     3315            present += extraEvents 
     3316 
     3317        if not present: 
     3318            present = [elem for elem in index[index.maxKey()]] 
     3319 
     3320        numPast = self._categ.getNumConferences() - len(present) - len(future) 
     3321        return present, future, len(future), numPast 
     3322 
     3323    def getVars( self ): 
     3324        vars = WTemplated.getVars( self ) 
     3325        displayTZ = DisplayTZ(self._aw, self._categ, useServerTZ=1).getDisplayTZ() 
     3326        vars["ActiveTimezone"] = displayTZ 
     3327        vars["presentItems"], vars["futureItems"], vars["numOfEventsInTheFuture"], vars["numOfEventsInThePast"] =  self.getEventTimeline(displayTZ) 
    33903328        vars["categ"] = self._categ 
    3391         vars["ActiveTimezone"] = DisplayTZ(self._aw,self._categ,useServerTZ=1).getDisplayTZ() 
     3329 
    33923330        vars["showPastEvents"] = self._showPastEvents 
    33933331 
  • indico/core/index/__init__.py

    rafb474 r080097  
    2121from indico.core.index.base import * 
    2222from indico.core.index.adapter import * 
     23from indico.core.index.catalog import Catalog 
  • indico/core/index/base.py

    r7257af r080097  
    2323 
    2424from BTrees.IOBTree import IOBTree, IOTreeSet 
    25 from BTrees.OOBTree import OOBTree, OOTreeSet, union 
     25from BTrees.OOBTree import OOBTree, OOTreeSet, OOSet, union 
    2626from persistent import Persistent 
    2727 
    28 import logging 
    2928import zope.interface 
    3029 
     
    6160 
    6261 
    63 class IOIndex(Persistent): 
    64     """ 
    65     Maps integer values to objects 
    66     int -> set(obj, ...) 
    67  
    68     int is obtained by means of an adapter 
     62class Index(Persistent): 
     63    pass 
     64 
     65 
     66class SIndex(Index): 
     67 
     68    _fwd_class = None 
     69    _fwd_set_class = None 
     70 
     71    def __init__(self, adapter): 
     72        self._adapter = adapter 
     73        self._fwd_index = self._fwd_class() 
     74        self._num_objs = Length(0) 
     75 
     76    def _gc_entry(self, v): 
     77        """ 
     78        'Garbage collect' empty set entries 
     79        """ 
     80        if len(self._fwd_index[v]) == 0: 
     81            del self._fwd_index[v] 
     82 
     83    def index_obj(self, obj): 
     84 
     85        value = self._adapter(obj) 
     86        vset = self._fwd_index.get(value, self._fwd_set_class()) 
     87 
     88        if obj in vset: 
     89            raise InconsistentIndexException("%s already in fwd[%s]", (obj, value)) 
     90        else: 
     91            vset.add(obj) 
     92            self._num_objs.change(1) 
     93 
     94        self._fwd_index[value] = vset 
     95 
     96    def _unindex_obj_from_key(self, key, obj): 
     97        if key in self._fwd_index: 
     98            vset = self._fwd_index[key] 
     99            if obj in vset: 
     100                vset.remove(obj) 
     101                self._fwd_index[key] = vset 
     102                self._gc_entry(key) 
     103            else: 
     104                raise InconsistentIndexException("'%s' not in fwd[%s]", 
     105                                                 (obj, key)) 
     106        else: 
     107            raise InconsistentIndexException("'%s' not in fwd index" % key) 
     108 
     109    def unindex_obj(self, obj): 
     110        """ 
     111        Slightly dumber than the one in DIndex, takes the indexation value (key) 
     112        instead of looking it up in the reverse index 
     113        """ 
     114        key = self._adapter(obj) 
     115        self._unindex_obj_from_key(key, obj) 
     116        self._num_objs.change(-1) 
     117 
     118 
     119    def values(self, *args): 
     120        res = self._fwd_set_class() 
     121        for s in self._fwd_index.itervalues(*args): 
     122            res = union(res, s) 
     123        return res 
     124 
     125    def itervalues(self, *args): 
     126        for s in self._fwd_index.itervalues(*args): 
     127            for t in s: 
     128                yield t 
     129 
     130    def iteritems(self, *args): 
     131        for ts, s in self._fwd_index.iteritems(*args): 
     132            for t in s: 
     133                yield ts, t 
     134 
     135    def minKey(self): 
     136        return self._fwd_index.minKey() 
     137 
     138    def maxKey(self): 
     139        return self._fwd_index.maxKey() 
     140 
     141    def __iter__(self): 
     142        return iter(self._fwd_index) 
     143 
     144    def __len__(self): 
     145        return self._num_objs() 
     146 
     147    def __getitem__(self, item): 
     148        return self._fwd_index[item] 
     149 
     150    def get(self, item, default=None): 
     151        return self._fwd_index.get(item, default) 
     152 
     153 
     154 
     155class DIndex(SIndex): 
     156    """ 
     157    Bidirectional Index Class 
    69158 
    70159    objects need to implement IUniqueIdProvider as well, as an id is needed for 
     
    72161    """ 
    73162 
     163    _rev_class = None 
     164    _rev_set_class = None 
     165 
    74166    def __init__(self, adapter): 
    75         self._fwd_index = IOBTree() 
    76         self._rev_index = OOBTree() 
    77         self._num_objs = Length(0) 
    78         self._adapter = adapter 
    79  
    80     def _gc_entry(self, v): 
    81         """ 
    82         'Garbage collect' empty set entries 
    83         """ 
    84         if len(self._fwd_index[v]) == 0: 
    85             del self._fwd_index[v] 
     167        super(DIndex, self).__init__(adapter) 
     168        self._rev_index = self._rev_class() 
    86169 
    87170    def index_obj(self, obj): 
     
    97180        value = self._adapter(obj) 
    98181 
    99         if uid not in self._rev_index: 
    100             ts = IOTreeSet() 
    101             self._rev_index[uid]  = ts 
    102  
    103         if value in self._rev_index[uid]: 
     182        ts = self._rev_index.get(uid, self._rev_set_class()) 
     183 
     184        if value in ts: 
    104185            raise ElementAlreadyInIndexException() 
    105186        else: 
    106             self._rev_index[uid].add(value) 
    107  
    108         vset = self._fwd_index.get(value) 
    109         if vset is None: 
    110             vset = OOTreeSet() 
    111             self._fwd_index[value] = vset 
    112  
    113         if obj in vset: 
    114             raise InconsistentIndexException("%s already in fwd[%s]", (obj, value)) 
    115         else: 
    116             vset.insert(obj) 
    117             self._num_objs.change(1) 
     187            ts.add(value) 
     188 
     189        self._rev_index[uid] = ts 
     190 
     191        super(DIndex, self).index_obj(obj) 
    118192 
    119193        return (uid, value) 
     
    124198 
    125199        if uid in self._rev_index: 
    126             values = self._rev_index[uid] 
     200            keys = self._rev_index[uid] 
    127201            del self._rev_index[uid] 
    128202 
    129             for v in values: 
    130                 if v in self._fwd_index: 
    131                     vset = self._fwd_index[v] 
    132                     if obj in vset: 
    133                         vset.remove(obj) 
    134                         self._gc_entry(v) 
    135                     else: 
    136                         raise InconsistentIndexException("%s not in fwd[%s]", 
    137                                                          (obj, v)) 
    138                 else: 
    139                     raise InconsistentIndexException("%s not in fwd index" % v) 
     203            for key in keys: 
     204                self._unindex_obj_from_key(key, obj) 
    140205        else: 
    141206            raise ElementNotFoundException(uid) 
     
    143208        self._num_objs.change(-1) 
    144209 
    145     def values(self, *args): 
    146         res = OOTreeSet() 
    147         for s in self._fwd_index.itervalues(*args): 
    148             res = union(res, s) 
    149         return res 
    150  
    151     def itervalues(self, *args): 
    152         for s in self._fwd_index.itervalues(*args): 
    153             for t in s: 
    154                 yield t 
    155  
    156     def iteritems(self): 
    157         for ts, s in self._fwd_index.iteritems(): 
    158             for t in s: 
    159                 yield ts, t 
    160  
    161     def minKey(self): 
    162         return self._fwd_index.minKey() 
    163  
    164     def maxKey(self): 
    165         return self._fwd_index.maxKey() 
    166  
    167     def __len__(self): 
    168         return self._num_objs() 
    169  
    170     def __getitem__(self, item): 
    171         return self._fwd_index[item] 
    172  
    173     def get(self, item): 
    174         return self._fwd_index[item] 
     210 
     211class SIOIndex(DIndex): 
     212    """ 
     213    Maps integer keys to objects 
     214    int -> set(obj) 
     215    """ 
     216    _fwd_class = IOBTree 
     217    _fwd_set_class = OOTreeSet 
     218 
     219 
     220class IOIndex(DIndex): 
     221    """ 
     222    Maps integer keys to objects 
     223    int -> set(obj) 
     224    uid(obj) -> set(int) 
     225    """ 
     226    _fwd_class = IOBTree 
     227    _rev_class = OOBTree 
     228    _fwd_set_class = OOTreeSet 
     229    _rev_set_class = IOTreeSet 
     230 
     231 
     232class OOIndex(DIndex): 
     233    """ 
     234    Maps object keys to objects 
     235    obj -> set(obj) 
     236    uid(obj) -> set(obj) 
     237    """ 
     238    _fwd_class = OOBTree 
     239    _rev_class = OOBTree 
     240    _fwd_set_class = OOSet 
     241    _rev_set_class = OOSet 
     242 
    175243 
    176244class IIIndex(FieldIndex): 
Note: See TracChangeset for help on using the changeset viewer.