The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/database/readSecondaryPreferred.ts

18 lines
811 B

import type { Db, ReadPreferenceLike } from 'mongodb';
import { ReadPreference } from 'mongodb';
export function readSecondaryPreferred(db?: Db, tags: any[] = []): ReadPreferenceLike {
const { readPreference } = db?.options || {};
if (tags.length) {
return new ReadPreference(ReadPreference.SECONDARY_PREFERRED, tags);
}
if (readPreference && readPreference instanceof ReadPreference && readPreference.tags?.length) {
return new ReadPreference(ReadPreference.SECONDARY_PREFERRED, readPreference.tags);
}
// For some reason the new ReadPreference definition requires the tags parameter even not been
// required by the code implementation and, for some reason, when passing an empty array it
// doesn't ignore the tags and stop using the secondaries.
return ReadPreference.SECONDARY_PREFERRED;
}