| Line 755... |
Line 755... |
| 755 |
@RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
755 |
@RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 756 |
public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
|
756 |
public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
|
| 757 |
List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
|
757 |
List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
|
| 758 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
758 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 759 |
|
759 |
|
| 760 |
// Pre-fetch FofoStore once (was being called for each webListing)
|
760 |
// Pre-fetch FofoStore once (instead of N times inside getDealResponses)
|
| 761 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
761 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
| 762 |
|
762 |
|
| 763 |
// Process all webListings in parallel using CompletableFuture
|
- |
|
| 764 |
List<CompletableFuture<Void>> futures = webListings.stream()
|
- |
|
| 765 |
.map(webListing -> CompletableFuture.runAsync(() -> {
|
763 |
for (WebListing webListing : webListings) {
|
| 766 |
try {
|
- |
|
| 767 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, fs, webListing, 0, 20));
|
764 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, fs, webListing, 0, 20));
|
| 768 |
} catch (Exception e) {
|
- |
|
| 769 |
logger.error("Error processing webListing {}: {}", webListing.getId(), e.getMessage());
|
- |
|
| 770 |
webListing.setFofoCatalogResponses(new ArrayList<>());
|
- |
|
| 771 |
}
|
- |
|
| 772 |
}))
|
765 |
}
|
| 773 |
.collect(Collectors.toList());
|
- |
|
| 774 |
|
- |
|
| 775 |
// Wait for all parallel tasks to complete
|
- |
|
| 776 |
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
- |
|
| 777 |
|
- |
|
| 778 |
return responseSender.ok(webListings);
|
766 |
return responseSender.ok(webListings);
|
| 779 |
}
|
767 |
}
|
| 780 |
|
768 |
|
| 781 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, FofoStore fs, WebListing webListing, int offset,
|
769 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, FofoStore fs, WebListing webListing, int offset,
|
| 782 |
int limit) throws Exception {
|
770 |
int limit) throws Exception {
|