Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions website/modules/asset/ui/src/scss/_cases.scss
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@
}
}

.is-hidden {
display: none !important;
}

.items-count {
font-weight: $font-weight-extra-bold;
color: $gray-500;
Expand Down
210 changes: 32 additions & 178 deletions website/modules/case-studies-page/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const mainWidgets = require('../../lib/mainWidgets');
const NavigationService = require('./services/NavigationService');
const SearchService = require('./services/SearchService');
const TagCountService = require('./services/TagCountService');
const UrlService = require('./services/UrlService');

const createDocMapById = function (docs) {
Expand Down Expand Up @@ -30,141 +28,6 @@ const collectFilterOptions = function (pieces, fieldName, docMap) {
return options;
};

const buildPiecesFiltersFromResults = async function (self, req, pieces) {
const [tags, partners] = await Promise.all([
self.apos.modules['cases-tags'].find(req).toArray(),
self.apos.modules['business-partner'].find(req).toArray(),
]);
const tagMap = createDocMapById(tags);
const partnerMap = createDocMapById(partners);
return {
industry: collectFilterOptions(pieces, 'industryIds', tagMap),
stack: collectFilterOptions(pieces, 'stackIds', tagMap),
caseStudyType: collectFilterOptions(pieces, 'caseStudyTypeIds', tagMap),
partner: collectFilterOptions(pieces, 'partnerIds', partnerMap),
};
};

const buildIndexQuery = function (self, req) {
const queryParams = { ...req.query };
const searchTerm = SearchService.getSearchTerm(queryParams);
delete queryParams.search;

const query = self.pieces
.find(req, {})
.applyBuildersSafely(queryParams)
.perPage(self.perPage);
self.filterByIndexPage(query, req.data.page);

const resolved = req.data.searchRelationships || {};
const searchCondition = SearchService.buildSearchCondition(
searchTerm,
resolved,
);
if (searchCondition) {
query.and(searchCondition);
}
return query;
};

const buildTagCountQuery = function (self, req) {
const queryParams = { ...req.query };
const searchTerm = SearchService.getSearchTerm(queryParams);
delete queryParams.search;
delete queryParams.page;

const query = self.pieces.find(req, {}).applyBuildersSafely(queryParams);
self.filterByIndexPage(query, req.data.page);

const resolved = req.data.searchRelationships || {};
const searchCondition = SearchService.buildSearchCondition(
searchTerm,
resolved,
);
if (searchCondition) {
query.and(searchCondition);
}
return query;
};

const runResolveSearchRelationships = async function (self, req) {
req.data ||= {};
const reqData = req.data;
const searchTerm = SearchService.getSearchTerm(req.query || {});
if (!searchTerm) {
reqData.searchRelationships = {};
return;
}
let resolvedRelationships = {};
try {
resolvedRelationships = await SearchService.resolveSearchRelationships(
searchTerm,
self.apos,
req,
);
} catch (error) {
self.apos.util.error('Error resolving search relationships:', error);
}
reqData.searchRelationships = resolvedRelationships;
};

const runApplyEnhancedSearchResults = async function (self, req) {
const reqData = req.data;
const searchTerm = SearchService.getSearchTerm(req.query || {});
if (!searchTerm) {
return;
}
const queryParams = { ...req.query };
delete queryParams.search;
const resolved = reqData.searchRelationships || {};
const hasRelationshipMatches = Object.keys(resolved).length > 0;
if (!hasRelationshipMatches) {
return;
}
const searchCondition = SearchService.buildSearchCondition(
searchTerm,
resolved,
);
if (!searchCondition) {
return;
}

const piecesQuery = self.pieces
.find(req, {})
.applyBuildersSafely(queryParams);
piecesQuery.and(searchCondition);

const pieces = await piecesQuery.toArray();
const totalPieces = pieces.length;
const piecesFilters = await buildPiecesFiltersFromResults(self, req, pieces);
reqData.pieces = pieces;
reqData.totalPieces = totalPieces;
reqData.totalPages = 1;
reqData.piecesFilters = piecesFilters;
};

const runSetupIndexData = async function (self, req) {
try {
const countQuery = buildTagCountQuery(self, req);
const caseStudiesForCounts = await countQuery.toArray();
const tagCounts = await TagCountService.calculateTagCounts(
req,
self.apos.modules,
self.options,
caseStudiesForCounts,
);
UrlService.attachIndexData(req, tagCounts);
} catch (error) {
self.apos.util.error('Error calculating tag counts:', error);
UrlService.attachIndexData(req, {
industry: {},
stack: {},
caseStudyType: {},
partner: {},
});
}
};

const buildIndexSeoData = function (req) {
const query = req.query || {};
const hasFilterParams =
Expand Down Expand Up @@ -214,13 +77,6 @@ module.exports = {
options: {
label: 'Case Studies Page',
pluralLabel: 'Case Studies Pages',
perPage: 6,
piecesFilters: [
{ name: 'industry' },
{ name: 'stack' },
{ name: 'caseStudyType' },
{ name: 'partner' },
],
pieces: 'case-studies',
piecesFiltersUrl: '/case-studies',
},
Expand All @@ -240,43 +96,41 @@ module.exports = {
},
},

init(self) {
const superBeforeIndex = self.beforeIndex;
self.beforeIndex = async (req) => {
if (superBeforeIndex) {
await superBeforeIndex(req);
}
await self.resolveSearchRelationships(req);
await self.applyEnhancedSearchResults(req);
await self.setupIndexData(req);
self.setupIndexSeoData(req);
};

const superBeforeShow = self.beforeShow;
self.beforeShow = async (req) => {
if (superBeforeShow) {
await superBeforeShow(req);
}
await self.setupShowData(req);
};
},

methods(self) {
return {
indexQuery(req) {
return buildIndexQuery(self, req);
},
resolveSearchRelationships(req) {
return runResolveSearchRelationships(self, req);
},
applyEnhancedSearchResults(req) {
return runApplyEnhancedSearchResults(self, req);
},
setupIndexData(req) {
return runSetupIndexData(self, req);
async beforeIndex(req) {
// Load all case studies and tags for frontend filtering
const [pieces, casesTags, businessPartners] = await Promise.all([
self.pieces.find(req).toArray(),
self.apos.modules['cases-tags'].find(req).toArray(),
self.apos.modules['business-partner'].find(req).toArray(),
]);
req.data.pieces = pieces;
req.data.totalPieces = pieces.length;
req.data.totalPages = 1;
req.data.casesTags = casesTags;
req.data.businessPartners = businessPartners;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🔵 Trivial

Unbounded load of every case study on each index render.

self.pieces.find(req).toArray() pulls the full corpus (with all projected fields) on every request to hydrate client-side filtering. As the number of case studies grows this increases DB load, memory, and rendered page size linearly with no ceiling. Consider capping the projection to only the fields the cards/data-search actually need, and confirm the total volume is expected to stay small.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@website/modules/case-studies-page/index.js` around lines 103 - 112, The case
studies index is loading the entire pieces collection on every render, which can
grow unbounded. Update the logic around self.pieces.find(req).toArray() in the
case-studies page handler to fetch only the fields needed by the cards and
data-search, and avoid projecting unused data. Keep the Promise.all flow for
casesTags and businessPartners, but cap the piece payload so req.data.pieces,
totalPieces, and totalPages are based on a minimal result set. If full corpus
loading is still intended, make that expectation explicit and ensure the dataset
is guaranteed to remain small.


// Build filter options from all tags
const tagMap = createDocMapById(casesTags);
const partnerMap = createDocMapById(businessPartners);
req.data.piecesFilters = {
industry: collectFilterOptions(pieces, 'industryIds', tagMap),
stack: collectFilterOptions(pieces, 'stackIds', tagMap),
caseStudyType: collectFilterOptions(pieces, 'caseStudyTypeIds', tagMap),
partner: collectFilterOptions(pieces, 'partnerIds', partnerMap),
};

// Attach URL helpers for template
UrlService.attachIndexData(req, {
industry: {},
stack: {},
caseStudyType: {},
partner: {},
});
},
setupIndexSeoData(req) {
return runSetupIndexSeoData(req);
async beforeShow(req) {
await self.setupShowData(req);
},
setupShowData(req) {
return runSetupShowData(self, req);
Expand Down
Loading
Loading