<commit_before>from twisted.internet import defer

#import txmongo
#from txmongo import gridfs
#from txmongo.collection import errors as mongo_errors
from tornado.ioloop import IOLoop
import motor
from pymongo.read_preferences import ReadPreference

from base import config


connection = None
db = None
fs = None
fs_avatars = None

def open_db():
    global db, fs
    client = motor.MotorReplicaSetClient(config.database_uri,read_preference=ReadPreference.NEAREST, replicaSet='shiplica')
    IOLoop.current().run_sync(client.open)
    db = client[config.database]
    fs = client[config.database_fs]

def get_db(collection=None):
    global db<commit_msg>Don't use replica set client when there is no replica.<commit_after>from twisted.internet import defer

#import txmongo
#from txmongo import gridfs
#from txmongo.collection import errors as mongo_errors
from tornado.ioloop import IOLoop
import motor
from pymongo.read_preferences import ReadPreference

from base import config


connection = None
db = None
fs = None
fs_avatars = None

def open_db():
    global db, fs
    if config.database_rs:
        client = motor.MotorReplicaSetClient(config.database_uri,read_preference=ReadPreference.NEAREST, replicaSet=config.database_rs)
    else:
        client = motor.MotorClient(config.database_uri,read_preference=ReadPreference.NEAREST)
    IOLoop.current().run_sync(client.open)
    db = client[config.database]
    fs = client[config.database_fs]

def get_db(collection=None):
    global db
{'fraction_non_alphanumeric': 0.0733822548365577, 'fraction_numerical': 0.0, 'mean_word_length': 5.048387096774194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '75460', 'n_tokens_mistral': 481, 'n_tokens_neox': 464, 'n_words': 123}