void UserStatSaveTask::handle() { StatMap stmap; StatManagerI::instance().popStatMap(stmap); if (stmap.empty()) { return; } Statement sql; string head = "insert into user_stat (userid,login_count,send_msg_count,rev_msg_count,online_buddy_count) values"; int count = 0; for (StatMap::iterator it = stmap.begin(); it != stmap.end(); ++it) { count++; if (count == 1) { sql.clear(); sql << head; } int onlineBuddy = 0; try { onlineBuddy = OnlineCenterAdapter::instance().getBuddyCount( it->first); } catch (Ice::Exception & e) { MCE_WARN("UserStatSaveTask::handle --> get OnlineBuddyCount err :" << e); } if (count > 1) { sql << ","; } sql << "(" << it->first << "," << it->second->loginCount << "," << it->second->msgCount << "," << it->second->revMsgCount << "," << onlineBuddy << ")"; if (count == 5000) { try { QueryRunner("im_stat", CDbWServer).schedule(sql); } catch (...) { MCE_WARN("UserStatSaveTask::handle --> do sql err"); } sql.clear(); count = 0; } } if (!sql.empty()) { try { QueryRunner("im_stat", CDbWServer).schedule(sql); } catch (...) { MCE_WARN("UserStatSaveTask::handle --> do sql err2"); } } }
void DBManager::SetToonStats(unsigned int charid, StatMap const& stats) { assert(charid != 0); TRACE("Updating stats on character id " << charid); m_db->Begin(); m_db->Exec(STREAM2STR("DELETE FROM tToonStats WHERE charid = " << charid)); for (StatMap::const_iterator it = stats.begin(); it != stats.end(); ++it) { unsigned int statid = it->first; unsigned int statvalue = it->second; m_db->Exec(STREAM2STR("INSERT OR IGNORE INTO tToonStats VALUES (" << charid << ", " << statid << ", " << statvalue << ")")); } m_db->Commit(); }