Skip to content

Commit

Permalink
short circuit searchEvents() if there are no sites to search
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwayson committed Feb 22, 2019
1 parent 7785f76 commit 371e642
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/events/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function formatEventResponse(
) {
const siteIds: string[] = [];
const data: IEventResourceObject[] = [];
const included: IEventResourceObject[] = [];
const cacheBust = new Date().getTime();
let siteSearchQuery = "";

Expand Down Expand Up @@ -128,14 +129,15 @@ function formatEventResponse(
siteSearchQuery += attributes.siteId;
}
});

if (siteIds.length === 0) {
return { included, data };
}
// search for site items and include those in the response
const searchRequestOptions = requestOptions as ISearchRequestOptions;
searchRequestOptions.searchForm = {
q: siteSearchQuery
};
return searchItems(searchRequestOptions).then(function(siteInfo) {
const included: IEventResourceObject[] = [];

siteInfo.results.forEach(siteItem => {
included.push({
id: siteItem.id,
Expand Down

0 comments on commit 371e642

Please sign in to comment.