@adobe/spacecat-shared-data-access 3.72.0 → 3.72.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [@adobe/spacecat-shared-data-access-v3.72.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.72.0...@adobe/spacecat-shared-data-access-v3.72.1) (2026-05-28)
2
+
3
+ ### Bug Fixes
4
+
5
+ * (data-access) include all fixes in getAllFixesWithSuggestionsByOpportunityId (SITES-45307) ([#1634](https://github.com/adobe/spacecat-shared/issues/1634)) ([49e073e](https://github.com/adobe/spacecat-shared/commit/49e073e9e79813597fb11a922fc9f561136ce1d8))
6
+
1
7
  ## [@adobe/spacecat-shared-data-access-v3.72.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.71.2...@adobe/spacecat-shared-data-access-v3.72.0) (2026-05-27)
2
8
 
3
9
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "3.72.0",
3
+ "version": "3.72.1",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -193,15 +193,15 @@ class FixEntityCollection extends BaseCollection {
193
193
 
194
194
  /**
195
195
  * Gets all fixes with their suggestions for a specific opportunity.
196
- * Fetches all junction records for the opportunity, then batch-loads
197
- * fix entities and suggestions. Actual PostgREST call count is
198
- * 1 + ceil(N/50) + ceil(M/50) due to batchGetByKeys chunking.
196
+ * Fetches fix entities and mapping records in parallel, then batch-loads
197
+ * suggestions. Fixes without mapping records are included with
198
+ * suggestions: [].
199
199
  *
200
200
  * @async
201
201
  * @param {string} opportunityId - The ID of the opportunity.
202
202
  * @returns {Promise<Array>} - A promise that resolves to an array of objects containing:
203
203
  * - fixEntity: The FixEntity model
204
- * - suggestions: Array of associated Suggestion models
204
+ * - suggestions: Array of associated Suggestion models (empty if none mapped)
205
205
  * @throws {DataAccessError} - Throws an error if the query fails.
206
206
  * @throws {ValidationError} - Throws an error if opportunityId is not provided.
207
207
  */
@@ -211,10 +211,12 @@ class FixEntityCollection extends BaseCollection {
211
211
  try {
212
212
  const fixEntitySuggestionCollection = this.entityRegistry.getCollection('FixEntitySuggestionCollection');
213
213
 
214
- const fixEntitySuggestions = await fixEntitySuggestionCollection
215
- .allByIndexKeys({ opportunityId });
214
+ const [allFixEntities, fixEntitySuggestions] = await Promise.all([
215
+ this.allByOpportunityId(opportunityId),
216
+ fixEntitySuggestionCollection.allByIndexKeys({ opportunityId }),
217
+ ]);
216
218
 
217
- return this.#buildFixesWithSuggestions(fixEntitySuggestions);
219
+ return this.#buildAllFixesWithSuggestions(allFixEntities, fixEntitySuggestions);
218
220
  } catch (error) {
219
221
  if (error instanceof DataAccessError) {
220
222
  throw error;
@@ -276,6 +278,44 @@ class FixEntityCollection extends BaseCollection {
276
278
 
277
279
  return result;
278
280
  }
281
+
282
+ async #buildAllFixesWithSuggestions(allFixEntities, fixEntitySuggestions) {
283
+ if (allFixEntities.length === 0) {
284
+ return [];
285
+ }
286
+
287
+ const suggestionIdsByFixEntityId = {};
288
+ for (const junction of fixEntitySuggestions) {
289
+ const fixEntityId = junction.getFixEntityId();
290
+ const suggestionId = junction.getSuggestionId();
291
+ if (!suggestionIdsByFixEntityId[fixEntityId]) {
292
+ suggestionIdsByFixEntityId[fixEntityId] = [];
293
+ }
294
+ suggestionIdsByFixEntityId[fixEntityId].push(suggestionId);
295
+ }
296
+
297
+ const allSuggestionIds = Object.values(suggestionIdsByFixEntityId).flat();
298
+ const suggestionsById = {};
299
+
300
+ if (allSuggestionIds.length > 0) {
301
+ const suggestionCollection = this.entityRegistry.getCollection('SuggestionCollection');
302
+ const suggestions = await suggestionCollection.batchGetByKeys(
303
+ allSuggestionIds.map((id) => ({ [suggestionCollection.idName]: id })),
304
+ );
305
+ for (const suggestion of suggestions.data) {
306
+ suggestionsById[suggestion.getId()] = suggestion;
307
+ }
308
+ }
309
+
310
+ return allFixEntities.map((fixEntity) => {
311
+ const fixEntityId = fixEntity.getId();
312
+ const suggestionIds = suggestionIdsByFixEntityId[fixEntityId] || [];
313
+ const suggestions = suggestionIds
314
+ .map((id) => suggestionsById[id])
315
+ .filter(Boolean);
316
+ return { fixEntity, suggestions };
317
+ });
318
+ }
279
319
  }
280
320
 
281
321
  export default FixEntityCollection;