mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 21:59:00 +02:00
75a12dda17
* [docstore] add useSecondary flag to projectHasRanges The rev-check for unarchiving always consults with the primary. Two extra changes: - Add a projection argument to peekDoc in order to skip lines download from projectHasRanges. - Add one retry to peekDoc to reduce chances of surfacing a rev-check violation. * [web] resync_projects: use the secondaries for all reads * [web] add default value for useSecondary * [docstore] add default value for useSecondary * [k8s] docstore: set MONGO_HAS_SECONDARIES=true GitOrigin-RevId: f15ec4fdc1cabe74c1eab87bec85f28d6f7a587d
38 lines
886 B
JavaScript
38 lines
886 B
JavaScript
// @ts-check
|
|
|
|
import Metrics from '@overleaf/metrics'
|
|
|
|
import Settings from '@overleaf/settings'
|
|
import MongoUtils from '@overleaf/mongo-utils'
|
|
import mongodb from 'mongodb-legacy'
|
|
|
|
const { MongoClient, ObjectId, BSON, ReadPreference } = mongodb
|
|
|
|
const mongoClient = new MongoClient(Settings.mongo.url, Settings.mongo.options)
|
|
const mongoDb = mongoClient.db()
|
|
|
|
const db = {
|
|
docs: mongoDb.collection('docs'),
|
|
}
|
|
|
|
Metrics.mongodb.monitor(mongoClient)
|
|
|
|
async function cleanupTestDatabase() {
|
|
await MongoUtils.cleanupTestDatabase(mongoClient)
|
|
}
|
|
|
|
const READ_PREFERENCE_PRIMARY = ReadPreference.primary.mode
|
|
const READ_PREFERENCE_SECONDARY = Settings.mongo.hasSecondaries
|
|
? ReadPreference.secondary.mode
|
|
: ReadPreference.secondaryPreferred.mode
|
|
|
|
export default {
|
|
READ_PREFERENCE_PRIMARY,
|
|
READ_PREFERENCE_SECONDARY,
|
|
db,
|
|
mongoClient,
|
|
ObjectId,
|
|
BSON,
|
|
cleanupTestDatabase,
|
|
}
|