@adobe/spacecat-shared-data-access 1.2.6 → 1.2.7
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 +7 -0
- package/package.json +1 -1
- package/src/service/sites/accessPatterns.js +25 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v1.2.7](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.6...@adobe/spacecat-shared-data-access-v1.2.7) (2023-12-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* sort order sites with latest audits ([#46](https://github.com/adobe-rnd/spacecat-shared/issues/46)) ([8da2bf1](https://github.com/adobe-rnd/spacecat-shared/commit/8da2bf16b904ced6787d8c56ba2b4b72678687a0))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-data-access-v1.2.6](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.5...@adobe/spacecat-shared-data-access-v1.2.6) (2023-12-11)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -55,19 +55,18 @@ export const getSitesToAudit = async (dynamoClient, config) => {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Retrieves sites with their latest audit
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
58
|
+
* Retrieves all sites with their latest audit. Sites without a latest audit will be included
|
|
59
|
+
* in the result, but will have an empty audits array. The sites are sorted by their latest
|
|
60
|
+
* audit scores in ascending order by default. The sortAuditsAscending parameter can be used
|
|
61
|
+
* to change the sort order. If a site has no latest audit, it will be sorted at the end of
|
|
62
|
+
* the list.
|
|
63
63
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
64
64
|
* @param {DataAccessConfig} config - The data access config.
|
|
65
65
|
* @param {Logger} log - The logger.
|
|
66
|
-
* @param {string} auditType - The type of
|
|
67
|
-
* @param {boolean} [sortAuditsAscending] -
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* each with its latest audit of the specified type.
|
|
66
|
+
* @param {string} auditType - The type of audits to retrieve for the sites.
|
|
67
|
+
* @param {boolean} [sortAuditsAscending=true] - Determines if the audits should be sorted in
|
|
68
|
+
* @return {Promise<Readonly<Site>[]>} A promise that resolves to an array of sites with their
|
|
69
|
+
* latest audit.
|
|
71
70
|
*/
|
|
72
71
|
export const getSitesWithLatestAudit = async (
|
|
73
72
|
dynamoClient,
|
|
@@ -81,17 +80,26 @@ export const getSitesWithLatestAudit = async (
|
|
|
81
80
|
getLatestAudits(dynamoClient, config, log, auditType, sortAuditsAscending),
|
|
82
81
|
]);
|
|
83
82
|
|
|
84
|
-
const
|
|
83
|
+
const sitesMap = new Map(sites.map((site) => [site.getId(), site]));
|
|
84
|
+
const orderedSites = [];
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
// First, append sites with a latest audit in the sorted order
|
|
87
|
+
latestAudits.forEach((audit) => {
|
|
88
|
+
const site = sitesMap.get(audit.getSiteId());
|
|
89
|
+
if (site) {
|
|
89
90
|
site.setAudits([audit]);
|
|
90
|
-
|
|
91
|
-
site.
|
|
91
|
+
orderedSites.push(site);
|
|
92
|
+
sitesMap.delete(site.getId()); // Remove the site from the map to avoid adding it again
|
|
92
93
|
}
|
|
93
|
-
return site;
|
|
94
94
|
});
|
|
95
|
+
|
|
96
|
+
// Then, append the remaining sites (without a latest audit)
|
|
97
|
+
sitesMap.forEach((site) => {
|
|
98
|
+
site.setAudits([]);
|
|
99
|
+
orderedSites.push(site);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return orderedSites;
|
|
95
103
|
};
|
|
96
104
|
|
|
97
105
|
/**
|