Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dedicated.ips): export csv with multiple call instead of 1 large #14816

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CSV_DATA_ENCODING,
CSV_DATA_SCHEME,
CSV_SEPARATOR,
FETCH_PAGE_SIZE,
} from './ip-ip-export.constants';
import { TRACKING_PREFIX } from '../list.constant';

Expand All @@ -14,6 +15,7 @@ export default /* @ngInject */ (
Alerter,
atInternet,
Ip,
$q,
) => {
let cancelFetch = null;

Expand All @@ -23,15 +25,45 @@ export default /* @ngInject */ (

function fetchIps() {
const { serviceType, otherParams } = $scope.currentActionData;
const { cancel, request } = Ip.fetchIps({
serviceType,
otherParams,
pageNumber: 1,
pageSize: 5000,
});
let pageNumber = 1;
const defered = $q.defer();
let allIps = [];

const cancel = () => {
defered.resolve(allIps);
};

try {
const { request: firstRequest } = Ip.fetchIps({
serviceType,
otherParams,
pageNumber,
pageSize: FETCH_PAGE_SIZE,
});

firstRequest.then(async ({ ips: firstIps }) => {
let ips = firstIps;
while (ips.length > 0) {
allIps = allIps.concat(ips);
pageNumber += 1;
const { request } = Ip.fetchIps({
serviceType,
otherParams,
pageNumber,
pageSize: FETCH_PAGE_SIZE,
});
/* eslint-disable no-await-in-loop */
({ ips } = await request);
}
defered.resolve(allIps);
});
} catch (error) {
defered.reject(error);
}

return {
cancel,
request: request.then(({ ips }) => ips),
request: defered.promise,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const CSV_HEADERS = [
},
];

export const FETCH_PAGE_SIZE = 100;
export const CSV_FILENAME = 'export_ips.csv';
export const CSV_DATA_ENCODING = 'base64';
export const CSV_DATA_SCHEME = `data:text/csv;charset=ISO-8859-1;${CSV_DATA_ENCODING}`;
Expand All @@ -36,4 +37,5 @@ export default {
CSV_DATA_ENCODING,
CSV_DATA_SCHEME,
CSV_SEPARATOR,
FETCH_PAGE_SIZE,
};
Loading