mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Refactor mongodb infra module to remove unneeded code
GitOrigin-RevId: f907753dffd67ed279815693c37498ec255f1353
This commit is contained in:
parent
56f70b3246
commit
777acc4040
1 changed files with 11 additions and 22 deletions
|
@ -40,30 +40,17 @@ async function waitForDb() {
|
||||||
|
|
||||||
const db = {}
|
const db = {}
|
||||||
|
|
||||||
let clientPromise
|
const mongoClient = new mongodb.MongoClient(
|
||||||
|
Settings.mongo.url,
|
||||||
async function getClient() {
|
Settings.mongo.options
|
||||||
if (!clientPromise) {
|
)
|
||||||
clientPromise = mongodb.MongoClient.connect(
|
|
||||||
Settings.mongo.url,
|
|
||||||
Settings.mongo.options
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return await clientPromise
|
|
||||||
}
|
|
||||||
|
|
||||||
addConnectionDrainer('mongodb', async () => {
|
addConnectionDrainer('mongodb', async () => {
|
||||||
const client = await getClient()
|
await mongoClient.close()
|
||||||
await client.close()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getInternalDb() {
|
|
||||||
const client = await getClient()
|
|
||||||
return client.db()
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setupDb() {
|
async function setupDb() {
|
||||||
const internalDb = await getInternalDb()
|
const internalDb = mongoClient.db()
|
||||||
|
|
||||||
db.contacts = internalDb.collection('contacts')
|
db.contacts = internalDb.collection('contacts')
|
||||||
db.deletedFiles = internalDb.collection('deletedFiles')
|
db.deletedFiles = internalDb.collection('deletedFiles')
|
||||||
|
@ -121,17 +108,19 @@ async function setupDb() {
|
||||||
db.onboardingDataCollection = internalDb.collection(
|
db.onboardingDataCollection = internalDb.collection(
|
||||||
'onboardingDataCollection'
|
'onboardingDataCollection'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await mongoClient.connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCollectionNames() {
|
async function getCollectionNames() {
|
||||||
const internalDb = await getInternalDb()
|
const internalDb = mongoClient.db()
|
||||||
|
|
||||||
const collections = await internalDb.collections()
|
const collections = await internalDb.collections()
|
||||||
return collections.map(collection => collection.collectionName)
|
return collections.map(collection => collection.collectionName)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dropTestDatabase() {
|
async function dropTestDatabase() {
|
||||||
const internalDb = await getInternalDb()
|
const internalDb = mongoClient.db()
|
||||||
const dbName = internalDb.databaseName
|
const dbName = internalDb.databaseName
|
||||||
const env = process.env.NODE_ENV
|
const env = process.env.NODE_ENV
|
||||||
|
|
||||||
|
@ -148,7 +137,7 @@ async function dropTestDatabase() {
|
||||||
* WARNING: Consider using a pre-populated collection from `db` to avoid typos!
|
* WARNING: Consider using a pre-populated collection from `db` to avoid typos!
|
||||||
*/
|
*/
|
||||||
async function getCollectionInternal(name) {
|
async function getCollectionInternal(name) {
|
||||||
const internalDb = await getInternalDb()
|
const internalDb = mongoClient.db()
|
||||||
return internalDb.collection(name)
|
return internalDb.collection(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue