def main(app): global TITLES, REDIRECTS start = time.time() print "Starting title server..." options = define_options() lb = LoadBalancer(options.dbconfig) global_db = lb.get_db_by_name('wikicities') (wiki_id, dbname) = get_local_db_from_options(options, global_db) local_db = lb.get_db_by_name(dbname) # store flat, unique dictionary cursor = local_db.cursor() cursor.execute("SELECT page_title FROM page WHERE page_namespace IN (%s)" % ", ".join(map(str, get_namespaces(global_db, wiki_id)))) TITLES = set(map(lambda x: preprocess(x[0]), cursor)) # relate preprocessed redirect title to canonical title cursor = local_db.cursor() cursor.execute( "SELECT page_title, rd_title FROM redirect INNER JOIN page ON page_id = rd_from" ) REDIRECTS = dict([map(preprocess, row) for row in cursor]) print "Title server ready in %s seconds" % str(time.time() - start) app.run(debug=True, host='0.0.0.0', port=5001)
def getIterator(self): lb = LoadBalancer( self.options.get('dbconf', '/usr/wikia/conf/current/DB.yml')) globalDb = lb.get_db_by_name('wikicities') cursor = globalDb.cursor() self.results = cursor.execute(self.getQuery()) self.progress = 0 return cursor
def initDb(self): dbyml = os.environ.get('WIKIA_DB_YML', '/usr/wikia/conf/current/DB.yml') lb = LoadBalancer(dbyml) globalDb = lb.get_db_by_name('wikicities') cursor = globalDb.cursor() cursor.execute('SELECT city_dbname FROM city_list WHERE city_url = "%s"' % (self.host)) result = cursor.fetchone() self.db = lb.get_db_by_name(result[0])
def get_local_db_from_wiki_id(global_db, wiki_id): global CURRENT_WIKI_ID cursor = get_global_db().cursor() sql = "SELECT city_id, city_dbname FROM city_list WHERE city_id = %s" % str( wiki_id) results = cursor.execute(sql) result = cursor.fetchone() if not result: raise ValueError("No wiki found") CURRENT_WIKI_ID = result[0] return LoadBalancer(get_config()).get_db_by_name(result[1])
def get_global_db(master=False): """ Accesses the wikia global db :param master: whether we should use the writeable master db :type master: bool :return: database connection :rtype: MySQLdb.connections.Connection """ lb = LoadBalancer(get_config()) return lb.get_db_by_name('wikicities', master=master)
def get_local_db_from_wiki_id(wiki_id, master=False): """ Accesses a given wiki's database :param wiki_id: the id of the wiki in the wikicities db :type wiki_id: int|str :param master: whether to use the writeable master :type master: bool :return: database connection :rtype: MySQLdb.connections.Connection """ global CURRENT_WIKI_ID cursor = get_global_db().cursor() sql = "SELECT city_id, city_dbname FROM city_list WHERE city_id = %s" % str( wiki_id) cursor.execute(sql) result = cursor.fetchone() if not result: raise ValueError("No wiki found") CURRENT_WIKI_ID = result[0] return LoadBalancer(get_config()).get_db_by_name(result[1], master=master)
def get_global_db(): lb = LoadBalancer(get_config()) return lb.get_db_by_name('wikicities')