Skip to content

Commit

Permalink
Merge pull request #1188 from akto-api-security/hotfix/faster_apiColl…
Browse files Browse the repository at this point in the history
…ectionsPage_loading

show some data first and the rest as loaded
  • Loading branch information
notshivansh authored Jun 13, 2024
2 parents 4bc5341 + 432d1cb commit adc89c5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public String fetchAllCollections() {
return Action.SUCCESS.toUpperCase();
}

public String fetchAllCollectionsBasic(){
this.apiCollections = ApiCollectionsDao.instance.findAll(new BasicDBObject());
return Action.SUCCESS.toUpperCase();
}

public String fetchCollection() {
this.apiCollections = new ArrayList<>();
this.apiCollections.add(ApiCollectionsDao.instance.findOne(Filters.eq(Constants.ID, apiCollectionId)));
Expand Down
11 changes: 11 additions & 0 deletions apps/dashboard/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,17 @@
<param name="status">401</param>
</result>
</action>

<action name="api/getAllCollectionsBasic" class="com.akto.action.ApiCollectionsAction" method="fetchAllCollectionsBasic">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<result name="SUCCESS" type="json">
</result>
<result name="ERROR" type="httpheader">
<param name="status">401</param>
</result>
</action>

<action name="api/getSensitiveInfoForCollections" class="com.akto.action.ApiCollectionsAction" method="fetchSensitiveInfoInCollections">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ export default {
data: {}
})
},
async getAllCollectionsBasic() {
return await request({
url: '/api/getAllCollectionsBasic',
method: 'post',
data: {}
})
},
async createCollection(name) {
return await request({
url: '/api/createCollection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ function ApiCollections() {

async function fetchData() {
setLoading(true)
let apiCollectionsResp = await api.getAllCollectionsBasic();
setLoading(false)
let tmp = (apiCollectionsResp.apiCollections || []).map(convertToCollectionData)
let envTypeObj = {}
tmp.forEach((c) => {
envTypeObj[c.id] = c.envType
})
setEnvTypeMap(envTypeObj)
let dataObj = {}
dataObj = convertToNewData(tmp, {}, {}, {}, {}, {});
let res = {}
res.all = dataObj.prettify
res.hostname = dataObj.prettify.filter((c) => c.hostName !== null && c.hostName !== undefined)
res.groups = dataObj.prettify.filter((c) => c.type === "API_GROUP")
res.custom = res.all.filter(x => !res.hostname.includes(x) && !res.groups.includes(x));
setData(res);

let apiPromises = [
api.getAllCollections(),
api.getCoverageInfoForCollections(),
Expand All @@ -188,15 +205,15 @@ function ApiCollections() {

let results = await Promise.allSettled(apiPromises);

let apiCollectionsResp = results[0].status === 'fulfilled' ? results[0].value : {};
apiCollectionsResp = results[0].status === 'fulfilled' ? results[0].value : {};
let coverageInfo = results[1].status === 'fulfilled' ? results[1].value : {};
let trafficInfo = results[2].status === 'fulfilled' ? results[2].value : {};
let hasUserEndpoints = results[3].status === 'fulfilled' ? results[3].value : true;
setHasUsageEndpoints(hasUserEndpoints)
setCoverageMap(coverageInfo)

let tmp = (apiCollectionsResp.apiCollections || []).map(convertToCollectionData)
let envTypeObj = {}
tmp = (apiCollectionsResp.apiCollections || []).map(convertToCollectionData)
envTypeObj = {}
tmp.forEach((c) => {
envTypeObj[c.id] = c.envType
})
Expand All @@ -206,9 +223,8 @@ function ApiCollections() {
const severityObj = issuesObj.severityObj;
const riskScoreObj = issuesObj.riskScoreObj;
const sensitiveInfo = await transform.fetchSensitiveInfo();
setLoading(false)

const dataObj = convertToNewData(tmp, sensitiveInfo.sensitiveInfoMap, severityObj, coverageInfo, trafficInfo, riskScoreObj?.riskScoreMap);
dataObj = convertToNewData(tmp, sensitiveInfo.sensitiveInfoMap, severityObj, coverageInfo, trafficInfo, riskScoreObj?.riskScoreMap);

const summary = transform.getSummaryData(dataObj.normal)
summary.totalCriticalEndpoints = riskScoreObj.criticalUrls;
Expand Down

0 comments on commit adc89c5

Please sign in to comment.