text
stringlengths
0
2.2M
bson_destroy(&q);
wlst.push_back(w);
}
sqli->endBulk();
} catch(const std::exception& e) {
throw e;
}
#endif
}
void TeBkUmMgrRouter::updateCache() {
#ifdef INC_SDORM_MONGO
CacheInterface* cchi = CacheManager::getImpl();
MongoDBRawDataSourceImpl* sqli = getDb();
try {
std::vector<TeBkUmMgrWorld> wlist;
sqli->begin(WORLD);
sqli->executeQuery(NULL, &wlist, &TeBkUmMgrRouter::updateCacheUtil);
sqli->end();
for (int c = 0; c < (int)wlist.size(); ++c) {
TeBkUmMgrWorld& w = wlist.at(c);
char str[12];
sprintf(str, "%d;%d", w.getId(), w.getRandomNumber());
cchi->setRaw(w.getId(), str);
}
CacheManager::cleanImpl(cchi);
CacheManager::triggerAppInitCompletion();
} catch(const std::exception& e) {
CacheManager::cleanImpl(cchi);
throw e;
}
#endif
}
#ifdef INC_SDORM_MONGO
void TeBkUmMgrRouter::updateCacheUtil(void* ctx, int rn, std::vector<MgRawRes>& data) {
std::vector<TeBkUmMgrWorld>* wlist = (std::vector<TeBkUmMgrWorld>*)ctx;
TeBkUmMgrWorld w;
for(int i=0;i<(int)data.size();i++) {
if(data.at(i).n=="_id") {
w.setId((int)data.at(i).d);
if(w.getId()<=0) {
w.setId((int)data.at(i).l);
}
}
if(data.at(i).n=="randomNumber") {
w.setRandomNumber((int)data.at(i).d);
if(w.getRandomNumber()<=0) {
w.setRandomNumber((int)data.at(i).l);
}
}
}
wlist->push_back(w);
}
#endif
void TeBkUmMgrRouter::cachedWorlds(const char* q, int ql, std::vector<TeBkUmMgrWorld>& wlst) {
int queryCount = 0;
strToNum(q, ql, queryCount);
if(queryCount<1)queryCount=1;
else if(queryCount>500)queryCount=500;
CacheInterface* cchi = CacheManager::getImpl();
try {
std::vector<unsigned long long> keys;
for (int c = 0; c < queryCount; ++c) {
int rid = rand() % 10000 + 1;
keys.emplace_back(rid);
}
std::vector<std::string> values;
cchi->getValues(keys, values);
for (int c = 0; c < queryCount; ++c) {
std::string& v = values.at(c);
size_t fn = v.find(";");
int tmp = 0;
CommonUtils::fastStrToNum(v.substr(0, fn).c_str(), fn, tmp);
int tmp1 = 0;
CommonUtils::fastStrToNum(v.substr(fn+1).c_str(), v.length()-fn-1, tmp1);
wlst.emplace_back(tmp, tmp1);
}
CacheManager::cleanImpl(cchi);
} catch(const std::exception& e) {
CacheManager::cleanImpl(cchi);
throw e;
}
}
void TeBkUmMgrRouter::getContext(HttpRequest* request, Context* context) {
#ifdef INC_SDORM_MONGO
MongoDBRawDataSourceImpl* sqli = getDb();
try {
std::vector<TeBkUmMgrFortune>* flst = new std::vector<TeBkUmMgrFortune>;
sqli->begin(FORTUNE);
sqli->executeQuery(NULL, flst, &TeBkUmMgrRouter::getContextUtil);
sqli->end();
TeBkUmMgrFortune nf;
nf.setId(0);