Skip to content
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
23 changes: 23 additions & 0 deletions website/modules/case-studies-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ const buildIndexQuery = function (self, req) {
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;
Expand Down Expand Up @@ -125,10 +145,13 @@ const runApplyEnhancedSearchResults = async function (self, req) {

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) {
Expand Down
20 changes: 14 additions & 6 deletions website/modules/case-studies-page/services/TagCountService.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ class TagCountService {
* @param {Object} options - Module options
* @returns {Promise<Array>} Promise resolving to [caseStudies, casesTags, businessPartners] arrays
*/
static async fetchCaseStudiesAndTags(req, aposModules, options) {
const [caseStudies, casesTags, businessPartners] = await Promise.all([
aposModules[options.pieces].find(req).toArray(),
static async fetchCaseStudiesAndTags(req, aposModules, options, caseStudies) {
const [casesTags, businessPartners] = await Promise.all([
aposModules['cases-tags'].find(req).toArray(),
aposModules['business-partner'].find(req).toArray(),
]);
return [caseStudies, casesTags, businessPartners];
let pieces = caseStudies;
if (!pieces) {
pieces = await aposModules[options.pieces].find(req).toArray();
}
return [pieces, casesTags, businessPartners];
}

/**
Expand Down Expand Up @@ -96,7 +99,7 @@ class TagCountService {
* @param {Object} options - Module options
* @returns {Promise<Object>} Tag counts by type
*/
static async calculateTagCounts(req, aposModules, options) {
static async calculateTagCounts(req, aposModules, options, caseStudiesInput) {
const tagCounts = {
industry: {},
stack: {},
Expand All @@ -105,7 +108,12 @@ class TagCountService {
};

const [caseStudies, casesTags, businessPartners] =
await TagCountService.fetchCaseStudiesAndTags(req, aposModules, options);
await TagCountService.fetchCaseStudiesAndTags(
req,
aposModules,
options,
caseStudiesInput,
);

const tagMap = TagCountService.createIdToSlugMap(casesTags);
const partnerMap = TagCountService.createIdToSlugMap(businessPartners);
Expand Down
Loading