I have 50k records in my oracle db and I need to export all the data to the csv file. It is using a native query in respository file.
Here is the controller file.
@PostMapping( value=Constants.DOWNLOAD)
@ApiOperation("download file for approvals")
public ResponseEntity<String> downloadFile(
@RequestBody @ApiParam(value = "Payload Body", required = true )
ApiDownload apiDownload) throws Exception {
try {
return mergeDebtService.downloadFile(apiDownload);
} catch (Exception e) {
e.printStackTrace();
throw new InvalidInputException(e.getMessage());
}
}
Here is the service file.
public ResponseEntity<String> downloadFile(ApiDownload apiDownload) throws Exception {
List<Integer> listIds = new ArrayList<Integer>();
List<Object[]> listObj = new ArrayList<>();
boolean blnAll=false;
if(UserMap.getRole()!=null && UserMap.getRole().equals("ADMIN")) {
listObj = ddmApprovalsRepository.findAllData(ddmUserMap.getProfileType());
}else {
listObj =ddmApprovalsRepository.findData(apiDownload.getLoginName());
}
}
File directory = new File("/tmp/uploads");
directory.mkdir();
Files.createDirectories(Paths.get("/tmp/uploads"));
try {
if(directory.exists()) {
FileUtils.deleteDirectory(directory);
directory.mkdir();
Files.createDirectories(Paths.get("/tmp/uploads"));
}
}catch (Exception e) {
// if the file is being accessed then it can throw error.
}
FILE_EXISTS=true;
ExcelFileGenerator fileGenerator = new ExcelFileGenerator();
String fileName =fileGenerator.generateCSVFile(listObj,
apiApprovalsDownload.getLoginName(),"/tmp/uploads",cbControlParams,blnAll);
File file = new File("/tmp/uploads/"+fileName);
return ResponseEntity.status(200).header("filename", fileName).body("downloaded
successfully");
}
It is taking almost 2 min to respond through the Api, how can I reduce the response timing. As it is giving 504 gateway timeout error .