static void benchThread( BenchRunConfig * config ) { ScopedDbConnection conn( config->host ); config->threadsReady++; while ( config->active ) { BSONObjIterator i( config->ops ); while ( i.more() ) { BSONElement e = i.next(); string ns = e["ns"].String(); string op = e["op"].String(); if ( op == "findOne" ) { conn->findOne( ns , fixQuery( e["query"].Obj() ) ); } else if ( op == "update" ) { conn->update( ns , fixQuery( e["query"].Obj() ) , e["update"].Obj() ); } else { log() << "don't understand op: " << op << endl; config->error = true; return; } } } conn.done(); }
static BSONObj fixQuery( const BSONObj& obj ) { if ( ! _hasSpecial( obj ) ) return obj; BSONObjBuilder b( obj.objsize() + 128 ); fixQuery( b , obj ); return b.obj(); }
void LastFmEngine::search(const QStringList &query, Mode mode) { QStringList fixedQuery=fixQuery(query); QUrl url("https://ws.audioscrobbler.com/2.0/"); #if QT_VERSION < 0x050000 QUrl &urlQuery=url; #else QUrlQuery urlQuery; #endif switch (mode) { case Artist: urlQuery.addQueryItem("method", "artist.getInfo"); break; case Album: urlQuery.addQueryItem("method", "album.getInfo"); urlQuery.addQueryItem("album", fixedQuery.at(1)); break; case Track: urlQuery.addQueryItem("method", "track.getInfo"); urlQuery.addQueryItem("track", fixedQuery.at(1)); break; } urlQuery.addQueryItem("api_key", Covers::constLastFmApiKey); urlQuery.addQueryItem("autocorrect", "1"); urlQuery.addQueryItem("artist", Covers::fixArtist(fixedQuery.at(0))); #if QT_VERSION >= 0x050000 url.setQuery(urlQuery); #endif job=NetworkAccessManager::self()->get(url); job->setProperty(constModeProperty, (int)mode); QStringList queryString; foreach (QString q, fixedQuery) { q=q.replace("/", "%2F"); q=q.replace(" ", "+"); queryString.append(q); }