Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOP-4044: Get repo branches for non-internal doc in docset #925

Merged
merged 9 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions modules/persistence/src/services/metadata/repos_branches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ReposBranchesDocument extends WithId<Document> {
branches: BranchEntry[];
url: EnvKeyedObject;
prefix: EnvKeyedObject;
internalOnly: boolean;
[key: string]: any;
}

Expand Down Expand Up @@ -82,7 +83,7 @@ export const getAllAssociatedRepoBranchesEntries = async (metadata: Metadata) =>

try {
const db = await pool();
const aggregationPipeline = getAggregationPipeline({ project: { $in: fetch } });
const aggregationPipeline = getAggregationPipeline({ project: { $in: fetch }, internalOnly: false });
const cursor = db.collection('docsets').aggregate(aggregationPipeline);
const docsets = (await cursor.toArray()) as ReposBranchesDocument[];
docsets.forEach((doc: ReposBranchesDocument) => {
Expand Down Expand Up @@ -114,20 +115,31 @@ export const getRepoBranchesEntry = async (project: project, branch = ''): Promi
// get from DB if not cached
try {
const db = await pool();
const matchCondition = { project };
const matchCondition = {
project,
// We want the repo branches of the single deployable repo for a docset
internalOnly: false,
};
if (branch) {
matchCondition['branches'] = { $elemMatch: { gitBranchName: branch } };
}
const aggregationPipeline = getAggregationPipeline(matchCondition);

const cursor = db.collection('docsets').aggregate(aggregationPipeline);
const res = (await cursor.toArray()) as unknown as ReposBranchesDocument[];
const returnedEntry = res[0];

if (res.length > 1) {
console.warn(
`Expected 1 deployable repo for docset with project "${project}", but found ${res.length} instead. Defaulting to first found: "${returnedEntry.repoName}".`
);
}

// if not already set, set cache value for repo_branches
if (!internals[project]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rayangler, this might be a silly question, but I see we are caching the value, but wouldn't we want to check the cache before querying the docsets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache is checked earlier here.

internals[project] = res[0];
internals[project] = returnedEntry;
}
return res[0];
return returnedEntry;
} catch (e) {
console.error(`Error while getting repo branches entry: ${e}`);
throw e;
Expand Down
60 changes: 60 additions & 0 deletions modules/persistence/tests/data/docsets.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,65 @@
"categoryTitle": "Atlas CLI"
},
"repos": ["6243aa3f0aae3635a59a1150"]
},
{
"_id": "6500937d24fcc731b4735cff",
"project": "docs",
"bucket": {
"regression": "docs-mongodb-org-stg",
"dev": "docs-mongodb-org-dev",
"stg": "docs-mongodb-org-stg",
"prd": "docs-mongodb-org-prd",
"dotcomstg": "docs-mongodb-org-dotcomstg",
"dotcomprd": "docs-mongodb-org-dotcomprd"
},
"directories": {
"snooty_toml": "/docs"
},
"prefix": {
"stg": "",
"prd": "",
"dotcomstg": "docs-qa",
"dotcomprd": "docs"
},
"repos": ["5fac1ce373a72fca02ec90c5", "614b9f5b8d181382ca755ade"],
"url": {
"regression": "https://docs-mongodbcom-integration.corp.mongodb.com",
"dev": "https://docs-mongodborg-staging.corp.mongodb.com",
"stg": "https://docs-mongodborg-staging.corp.mongodb.com",
"prd": "https://docs.mongodb.com",
"dotcomprd": "http://mongodb.com/",
"dotcomstg": "https://mongodbcom-cdn.website.staging.corp.mongodb.com/"
}
},
{
"_id": "6500937d24fcc731b4735d00",
"project": "multiple-deployables",
"bucket": {
"regression": "docs-mongodb-org-stg",
"dev": "docs-mongodb-org-dev",
"stg": "docs-mongodb-org-stg",
"prd": "docs-mongodb-org-prd",
"dotcomstg": "docs-mongodb-org-dotcomstg",
"dotcomprd": "docs-mongodb-org-dotcomprd"
},
"directories": {
"snooty_toml": "/docs"
},
"prefix": {
"stg": "",
"prd": "",
"dotcomstg": "docs-qa",
"dotcomprd": "docs"
},
"repos": ["6526fe0d17c4f50e837e419f", "6526fe0d17c4f50e837e420f"],
"url": {
"regression": "https://docs-mongodbcom-integration.corp.mongodb.com",
"dev": "https://docs-mongodborg-staging.corp.mongodb.com",
"stg": "https://docs-mongodborg-staging.corp.mongodb.com",
"prd": "https://docs.mongodb.com",
"dotcomprd": "http://mongodb.com/",
"dotcomstg": "https://mongodbcom-cdn.website.staging.corp.mongodb.com/"
}
}
]
Loading
Loading