Skip to content

Commit

Permalink
DOP-5036 casing
Browse files Browse the repository at this point in the history
  • Loading branch information
anabellabuckvar committed Sep 30, 2024
1 parent a0609b5 commit 0557a19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
5 changes: 3 additions & 2 deletions search-manifest/src/assertEnvVars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const assertEnvVars = (vars: any) => {
const assertEnvVars = (vars: any) => {
const missingVars = Object.entries(vars)
.filter(([, value]) => !value)
.map(([key]) => `- ${key}`)
Expand All @@ -18,5 +18,6 @@ export const getEnvVars = () => {
DOCSETS_COLLECTION: "docsets",
DOCUMENTS_COLLECTION: "documents",
};
if (assertEnvVars(ENV_VARS)) return ENV_VARS;
assertEnvVars(ENV_VARS);
return ENV_VARS;
};
39 changes: 15 additions & 24 deletions search-manifest/src/uploadToAtlas/searchConnector.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import type { Db } from "mongodb";
import * as mongodb from "mongodb";
import type { DatabaseDocument } from "../types";
import { getEnvVars } from "../assertEnvVars";

// We should only ever have one client active at a time.

// cached db object, so we can handle initial connection process once if unitialized

const ATLAS_CLUSTER0_URI = `mongodb+srv://${process.env.MONGO_ATLAS_USERNAME}:${process.env.MONGO_ATLAS_PASSWORD}@${process.env.MONGO_ATLAS_CLUSTER0_HOST}/?retryWrites=true&w=majority`;
const SNOOTY_DB_NAME = `${process.env.MONGO_ATLAS_POOL_DB_NAME}`;

const ATLAS_SEARCH_URI = `mongodb+srv://${process.env.MONGO_ATLAS_USERNAME}:${process.env.MONGO_ATLAS_PASSWORD}@${process.env.MONGO_ATLAS_SEARCH_HOST}/?retryWrites=true&w=majority`;
const SEARCH_DB_NAME = `${process.env.MONGO_ATLAS_SEARCH_DB_NAME}`;

const REPOS_BRANCHES_COLLECTION = "repos_branches";
const DOCSETS_COLLECTION = "docsets";
const DOCUMENTS_COLLECTION = "documents";
const ENV_VARS = getEnvVars();

let searchDb: mongodb.MongoClient;
let snootyDb: mongodb.MongoClient;
Expand All @@ -37,24 +26,24 @@ export const dbClient = async (uri: string) => {
};

export const getSearchDb = async () => {
console.log("getting search db");
const uri = ATLAS_SEARCH_URI;
const dbName = SEARCH_DB_NAME;
console.log("Getting search Db");
const uri = ENV_VARS.ATLAS_SEARCH_URI;
const dbName = ENV_VARS.SEARCH_DB_NAME;
if (searchDb) {
console.log("search db client already exists, using existing instance");
console.log("search Db client already exists, using existing instance");
} else {
searchDb = await dbClient(uri);
}
return searchDb.db(dbName);
};

export const getSnootyDb = async () => {
console.log("getting snooty db");
const uri = ATLAS_CLUSTER0_URI;
const dbName = SNOOTY_DB_NAME;
console.log("Getting snooty Db");
const uri = ENV_VARS.ATLAS_CLUSTER0_URI;
const dbName = ENV_VARS.SNOOTY_DB_NAME;

if (snootyDb) {
console.log("snooty db client already exists, using existing instance");
console.log("Snooty Db client already exists, using existing instance");
} else {
snootyDb = await dbClient(uri);
}
Expand All @@ -77,15 +66,17 @@ export const closeSearchDb = async () => {

export const getDocsetsCollection = async () => {
const dbSession = await getSnootyDb();
return dbSession.collection<DatabaseDocument>(DOCSETS_COLLECTION);
return dbSession.collection<DatabaseDocument>(ENV_VARS.DOCSETS_COLLECTION);
};

export const getReposBranchesCollection = async () => {
const dbSession = await getSnootyDb();
return dbSession.collection<DatabaseDocument>(REPOS_BRANCHES_COLLECTION);
return dbSession.collection<DatabaseDocument>(
ENV_VARS.REPOS_BRANCHES_COLLECTION
);
};

export const getDocumentsCollection = async () => {
const dbSession = await getSearchDb();
return dbSession.collection<DatabaseDocument>(DOCUMENTS_COLLECTION);
return dbSession.collection<DatabaseDocument>(ENV_VARS.DOCUMENTS_COLLECTION);
};

0 comments on commit 0557a19

Please sign in to comment.