Do not run storeBuddy for buddies from database. Run all updates in one transaction

This commit is contained in:
HanzZ 2012-07-29 05:59:55 +02:00
parent 6efc5e055b
commit 47af5069d3
3 changed files with 5 additions and 11 deletions

View file

@ -205,7 +205,6 @@ int MySQLBackend::Statement::execute() {
m_offset = 0;
m_resultOffset = 0;
int ret;
if ((ret = mysql_stmt_execute(m_stmt)) != 0) {
LOG4CXX_ERROR(logger, m_string << " " << mysql_stmt_error(m_stmt) << "; " << mysql_error(m_conn));
return mysql_stmt_errno(m_stmt);
@ -479,13 +478,11 @@ long MySQLBackend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
void MySQLBackend::updateBuddy(long userId, const BuddyInfo &buddyInfo) {
// "UPDATE " + m_prefix + "buddies SET groups=?, nickname=?, flags=?, subscription=? WHERE user_id=? AND uin=?"
std::string groups = Util::serializeGroups(buddyInfo.groups);
LOG4CXX_INFO(logger, "update buddy '" << groups << "' '" << buddyInfo.alias << "' '" << buddyInfo.flags << "' '" << buddyInfo.subscription << "' '" << userId << "' '" << buddyInfo.legacyName);
*m_updateBuddy << groups;
*m_updateBuddy << buddyInfo.alias << buddyInfo.flags << buddyInfo.subscription;
*m_updateBuddy << userId << buddyInfo.legacyName;
EXEC(m_updateBuddy, updateBuddy(userId, buddyInfo));
LOG4CXX_INFO(logger, "update buddy done");
}
bool MySQLBackend::getBuddies(long id, std::list<BuddyInfo> &roster) {
@ -610,11 +607,11 @@ void MySQLBackend::updateUserSetting(long id, const std::string &variable, const
}
void MySQLBackend::beginTransaction() {
//exec("START TRANSACTION;");
exec("START TRANSACTION;");
}
void MySQLBackend::commitTransaction() {
//exec("COMMIT;");
exec("COMMIT;");
}
}

View file

@ -515,7 +515,7 @@ void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
if (m_rosterStorage || !storageBackend) {
return;
}
m_rosterStorage = new RosterStorage(m_user, storageBackend);
RosterStorage *storage = new RosterStorage(m_user, storageBackend);
std::list<BuddyInfo> roster;
storageBackend->getBuddies(m_user->getUserInfo().id, roster);
@ -526,6 +526,8 @@ void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
m_buddies[buddy->getName()] = buddy;
onBuddySet(buddy);
}
m_rosterStorage = storage;
}
Swift::RosterPayload::ref RosterManager::generateRosterPayload() {

View file

@ -114,20 +114,16 @@ bool RosterStorage::storeBuddies() {
m_storageBackend->beginTransaction();
for (std::map<std::string, Buddy *>::const_iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
LOG4CXX_INFO(logger, "storing 1");
Buddy *buddy = (*it).second;
BuddyInfo buddyInfo;
buddyInfo.alias = buddy->getAlias();
LOG4CXX_INFO(logger, "storing 1.5");
buddyInfo.legacyName = buddy->getName();
buddyInfo.groups = buddy->getGroups();
LOG4CXX_INFO(logger, "storing 2");
buddyInfo.subscription = buddy->getSubscription() == Buddy::Ask ? "ask" : "both";
buddyInfo.id = buddy->getID();
buddyInfo.flags = buddy->getFlags();
buddyInfo.settings["icon_hash"].s = buddy->getIconHash();
buddyInfo.settings["icon_hash"].type = TYPE_STRING;
LOG4CXX_INFO(logger, "storing 3");
// Buddy is in DB
if (buddyInfo.id != -1) {
@ -137,7 +133,6 @@ bool RosterStorage::storeBuddies() {
buddyInfo.id = m_storageBackend->addBuddy(m_user->getUserInfo().id, buddyInfo);
buddy->setID(buddyInfo.id);
}
LOG4CXX_INFO(logger, "storing 4");
// Log("buddyListSaveNode", id << " " << name << " " << alias << " " << s_buddy->getSubscription());
// if (s_buddy->getBuddy() && id != -1) {