X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/53e3e5c4fa09c1ca7e1cb44054ec38441125868c..892385e632dee65c9eac60ba3a358e9e95d4a193:/projects/stargazer/user.cpp diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user.cpp index 989d11b5..46f6848b 100644 --- a/projects/stargazer/user.cpp +++ b/projects/stargazer/user.cpp @@ -115,7 +115,6 @@ ips = StrToIPS("*"); deleted = false; lastWriteStat = stgTime + random() % settings->GetStatWritePeriod(); lastWriteDeatiledStat = stgTime; -lastSwapDeatiledStat = stgTime; property.tariffName.AddBeforeNotifier(&tariffNotifier); property.passive.AddBeforeNotifier(&passiveNotifier); @@ -197,7 +196,6 @@ deleted = u.deleted; lastWriteStat = u.lastWriteStat; lastWriteDeatiledStat = u.lastWriteDeatiledStat; -lastSwapDeatiledStat = u.lastSwapDeatiledStat; settings = u.settings; @@ -940,22 +938,18 @@ Run(); //----------------------------------------------------------------------------- int USER::WriteDetailStat(bool hard) { -printfd(__FILE__, "USER::WriteDetailedStat() - queue size = %d\n", traffStatQueue.size()); +printfd(__FILE__, "USER::WriteDetailedStat() - saved size = %d\n", traffStatSaved.second.size()); -if (!traffStatQueue.empty()) +if (!traffStatSaved.second.empty()) { - std::list >::iterator it; - for (it = traffStatQueue.begin(); it != traffStatQueue.end(); ++it) + if (store->WriteDetailedStat(traffStatSaved.second, traffStatSaved.first, login)) { - if (store->WriteDetailedStat(it->second, it->first, login)) - { - printfd(__FILE__, "USER::WriteDetailStat() - failed to write detail stat from queue\n"); - WriteServLog("Cannot write detail stat from queue (of size %d recs) for user %s.", traffStatQueue.size(), login.c_str()); - WriteServLog("%s", store->GetStrError().c_str()); - return -1; - } - traffStatQueue.erase(it++); + printfd(__FILE__, "USER::WriteDetailStat() - failed to write detail stat from queue\n"); + WriteServLog("Cannot write detail stat from queue (of size %d recs) for user %s.", traffStatSaved.second.size(), login.c_str()); + WriteServLog("%s", store->GetStrError().c_str()); + return -1; } + traffStatSaved.second.erase(traffStatSaved.second.begin(), traffStatSaved.second.end()); } TRAFF_STAT ts; @@ -977,8 +971,11 @@ if (ts.size() && !disabledDetailStat) if (!hard) { printfd(__FILE__, "USER::WriteDetailStat() - pushing detail stat to queue\n"); - traffStatQueue.push_back(std::make_pair(lastWriteDeatiledStat, ts)); + STG_LOCKER lock(&mutex, __FILE__, __LINE__); + traffStatSaved.second.swap(ts); + traffStatSaved.first = lastWriteDeatiledStat; } + return -1; } } lastWriteDeatiledStat = stgTime;