Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.
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
6 changes: 4 additions & 2 deletions .github/workflows/test-persistence.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:
jobs:
# Checks for changes to the modules/persistence directory
changes:
runs-on: ubuntu-latest
# locking to ubuntu 22.04 to allow mongodb-memory-server to run
runs-on: ubuntu-22.04
outputs:
persistence: ${{ steps.filter.outputs.persistence }}
steps:
Expand All @@ -29,7 +30,8 @@ jobs:
defaults:
run:
working-directory: 'modules/persistence'
runs-on: ubuntu-latest
# locking to ubuntu 22.04 to allow mongodb-memory-server to run
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
Expand Down
14 changes: 13 additions & 1 deletion modules/persistence/src/services/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ interface PageAst {
[key: string]: any;
}

interface Facet {
category: string;
value: string;
display_name: string;
sub_facets?: { [key: string]: any }[];
}

export interface Page {
page_id: string;
filename: string;
ast: PageAst;
static_assets: UpdatedAsset[];
github_username: string;
facets?: Facet[];
}

export interface UpdatedPage extends Page {
Expand All @@ -35,6 +43,7 @@ interface PreviousPageMapping {
[key: string]: {
ast: PageAst;
static_assets: StaticAsset[];
facets?: Facet[];
};
}

Expand Down Expand Up @@ -75,6 +84,7 @@ const findPrevPageDocs = async (pageIdPrefix: string, collection: string, github
page_id: 1,
ast: 1,
static_assets: 1,
facets: 1,
};

try {
Expand All @@ -96,6 +106,7 @@ const createPageAstMapping = async (docsCursor: FindCursor) => {
mapping[doc.page_id] = {
ast: doc.ast,
static_assets: doc.static_assets,
facets: doc.facets,
};
pageIds.add(doc.page_id);
}
Expand Down Expand Up @@ -148,7 +159,7 @@ class UpdatedPagesManager {

// Update the document if page's current AST is different from previous build's.
// New pages should always count as having a "different" AST
if (!isEqual(page.ast, prevPageData?.ast)) {
if (!isEqual(page.ast, prevPageData?.ast) || !isEqual(page.facets, prevPageData?.facets)) {
const operation = {
updateOne: {
filter: { page_id: currentPageId, github_username: page.github_username },
Expand All @@ -162,6 +173,7 @@ class UpdatedPagesManager {
deleted: false,
// Track the last build ID to update the content
build_id: this.buildId,
facets: page.facets,
},
$setOnInsert: {
created_at: this.updateTime,
Expand Down
43 changes: 43 additions & 0 deletions modules/persistence/tests/services/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,49 @@ describe('pages module', () => {
expect(res[0].updated_at !== res[1].updated_at).toBeTruthy();
});

it('should update pages with modified facets', async () => {
const pagePrefix = generatePagePrefix();
const pages = generatePages(pagePrefix);
await _updatePages(pages, collection, GH_USER, new ObjectID());
// Applying facet updates to both pages
const updatedPages = generatePages(pagePrefix);
updatedPages[0].facets = [
{
category: 'target_product',
value: 'atlas',
display_name: 'Atlas',
},
];
updatedPages[1].facets = [
{
category: 'target_product',
value: 'atlas',
display_name: 'Atlas',
sub_facets: [{ category: 'sub_product', value: 'kubernetes-operator', display_name: 'Kubernetes Operator' }],
},
];

const findQuery = {
page_id: { $regex: new RegExp(`^${pagePrefix}`) },
};
await _updatePages(updatedPages, collection, GH_USER, new ObjectID());
const res = await mockDb.collection<UpdatedPage>(collection).find(findQuery).toArray();
expect(res).toHaveLength(2);
expect(res.every(({ facets }) => facets && facets.length)).toBeTruthy();
expect(res[1]).toHaveProperty('facets[0].sub_facets[0].value');

// removal of facet also propagates to update
const removedFacetUpdates = generatePages(pagePrefix).slice(0, 1);
delete removedFacetUpdates[0].facets;

await _updatePages(removedFacetUpdates, collection, GH_USER, new ObjectID());
const findRemovalQuery = {
page_id: { $regex: new RegExp(`^${pagePrefix}/page0.txt`) },
};
const removeFacetRes = await mockDb.collection<UpdatedPage>(collection).find(findRemovalQuery).toArray();
expect(removeFacetRes[0].facets).toBeNull();
});

it('should mark pages for deletion', async () => {
const pagePrefix = generatePagePrefix();
const pages = generatePages(pagePrefix);
Expand Down
Loading