Changeset - 47af5069d3fb
[Not reviewed]
0 3 0
HanzZ - 13 years ago 2012-07-29 05:59:55
hanzz.k@gmail.com
Do not run storeBuddy for buddies from database. Run all updates in one transaction
3 files changed with 5 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/mysqlbackend.cpp
Show inline comments
 
@@ -202,13 +202,12 @@ MySQLBackend::Statement::~Statement() {
 
int MySQLBackend::Statement::execute() {
 
	// If statement has some input and doesn't have any output, we have
 
	// to clear the offset now, because operator>> will not be called.
 
	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);
 
	}
 
	return 0;
 
}
 
@@ -476,19 +475,17 @@ long MySQLBackend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
 
	return id;
 
}
 

	
 
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) {
 
//	SELECT id, uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC
 
	*m_getBuddies << id;
 

	
 
@@ -607,16 +604,16 @@ void MySQLBackend::updateUserSetting(long id, const std::string &variable, const
 
// 	"UPDATE " + m_prefix + "users_settings SET value=? WHERE user_id=? AND var=?"
 
	*m_updateUserSetting << value << id << variable;
 
	EXEC(m_updateUserSetting, updateUserSetting(id, variable, value));
 
}
 

	
 
void MySQLBackend::beginTransaction() {
 
	//exec("START TRANSACTION;");
 
	exec("START TRANSACTION;");
 
}
 

	
 
void MySQLBackend::commitTransaction() {
 
	//exec("COMMIT;");
 
	exec("COMMIT;");
 
}
 

	
 
}
 

	
 
#endif
src/rostermanager.cpp
Show inline comments
 
@@ -512,23 +512,25 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
 
}
 

	
 
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);
 

	
 
	for (std::list<BuddyInfo>::const_iterator it = roster.begin(); it != roster.end(); it++) {
 
		Buddy *buddy = m_component->getFactory()->createBuddy(this, *it);
 
		LOG4CXX_INFO(logger, m_user->getJID().toString() << ": Adding cached buddy " << buddy->getName() << " fom database");
 
		m_buddies[buddy->getName()] = buddy;
 
		onBuddySet(buddy);
 
	}
 

	
 
	m_rosterStorage = storage;
 
}
 

	
 
Swift::RosterPayload::ref RosterManager::generateRosterPayload() {
 
	Swift::RosterPayload::ref payload = Swift::RosterPayload::ref(new Swift::RosterPayload());
 

	
 
	for (std::map<std::string, Buddy *, std::less<std::string>, boost::pool_allocator< std::pair<std::string, Buddy *> > >::iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
src/rosterstorage.cpp
Show inline comments
 
@@ -111,36 +111,31 @@ bool RosterStorage::storeBuddies() {
 
		return false;
 
	}
 
	
 
	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) {
 
			m_storageBackend->updateBuddy(m_user->getUserInfo().id, buddyInfo);
 
		}
 
		else {
 
			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) {
 
// 			PurpleBuddy *buddy = s_buddy->getBuddy();
 
// 			SaveData *s = new SaveData;
 
// 			s->user = user;
0 comments (0 inline, 0 general)