def createChatroom(cls, obj, params): """ Inserts the object in the database according to all the kind of indexing types, in this case: -Chat rooms by conference -Chat rooms by user -Chat rooms by name (to check if there's already a chat room with that name in our XMPP server) -Chat rooms by ID (to access faster to the object when querying) """ room = params['room'] conference = params['conference'] # index by conference id confIndex = IndexByConf() room.setId(DBHelpers.newID()) confIndex.index(conference.getId(), room) # Index by chat room's name crNameIndex = IndexByCRName() crNameIndex.index(room) # Index by id idIndex = IndexByID() idIndex.index(room) # Index by room creator userIndex = IndexByUser() userIndex.index(room.getOwner().getId(), room)
def editChatroom(self, obj, params): oldTitle = params['oldTitle'] newRoom = params['newRoom'] #we have an index by the chat room name. If, while editing, someone changes the chat room name, we'll have to update the index if oldTitle != newRoom.getTitle(): #the title has been changed. Get rid of the old index and substitute it for the new one crNameIndex = IndexByCRName() crNameIndex.unindex(newRoom, oldTitle) crNameIndex.index(newRoom)
def editChatroom(self, obj, params): oldTitle = params['oldTitle'] newRoom = params['newRoom'] userId = params['userId'] #we have an index by the chat room name. If, while editing, someone changes the chat room name, we'll have to update the index if oldTitle != newRoom.getTitle(): #the title has been changed. Get rid of the old index and substitute it for the new one crNameIndex = IndexByCRName() crNameIndex.unindex(newRoom, oldTitle) crNameIndex.index(newRoom) # For dynamic loading this needs to be in alphabetical order, # therefore reindex on change. userIndex = IndexByUser() userIndex.reindex(userId, newRoom, oldTitle)
def chatroomIndexMigration(dbi, withRBDB, prevVersion): """ Migrating Chat Room index to new structure """ # The structure of the indexes is such that for each one self._data # is a BTree and each node is referenced by the IndexBy___ designation, # where ___ is the ID in question. Each node is then a TreeSet of # ChatRoom or XMPPChatRoom objects originally orderded by ID, we need # this to be ordered by title for effective searching / querying. # The __cmp__ method has been altered to accommodate this new format, # take each subnode, iterate through saving the current objects, clear the # index and reinsert them - they will now be in the correct order. from MaKaC.plugins.InstantMessaging.indexes import IndexByUser, IndexByConf, IndexByCRName, IndexByID im_plugin = PluginsHolder().getPluginType('InstantMessaging') if not im_plugin.isUsable(): print console.colored(' IM plugin not usable - jumping task', 'yellow') return try: for idx in [IndexByUser(), IndexByConf(), IndexByCRName()]: tmp_idx = defaultdict(list) print console.colored(" * Index: " + str(idx), 'blue') for key, node in idx._data.iteritems(): for leaf in node: tmp_idx[key].append(leaf) # reset index idx._data.clear() for accum, rooms in tmp_idx.iteritems(): for room in rooms: # Specific handling as IndexByUser & IndexByConf have different # arguements for tree insertion. if isinstance(idx, IndexByUser) or isinstance( idx, IndexByConf): idx.index(str(accum), room) else: idx.index(room) print console.colored( "\tAll indexes have now been re-indexed and committed to the DB.", 'green') except: dbi.abort() print console.colored( "Process failed, ended abruptly, changes not committed.", 'red') raise
def deleteChatroom(cls, obj, params): """ Deletes the chat room in the database according to all kind of indexing types""" chatroom = params['room'] confId = obj._conferenceID #if we have the same room used in two or more different conferences, we just delete it from the #conferences list in the chat room and from the IndexByConf index chatroom.getConferences().pop(confId) confIndex = IndexByConf() confIndex.unindex(confId, chatroom) if len(chatroom.getConferences()) is 0: #there are no more references to the chat room, we completely delete it crNameIndex = IndexByCRName() crNameIndex.unindex(chatroom) idIndex = IndexByID() idIndex.unindex(chatroom) userIndex = IndexByUser() userIndex.unindex(chatroom.getOwner().getId(), chatroom)