| Line 120... |
Line 120... |
| 120 |
.filter(x -> x.getShortPercentage() <= 10)
|
120 |
.filter(x -> x.getShortPercentage() <= 10)
|
| 121 |
.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
|
121 |
.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
|
| 122 |
|
122 |
|
| 123 |
LOGGER.info("investmentMaintainedDaysMap" + investmentMaintainedDaysMap);
|
123 |
LOGGER.info("investmentMaintainedDaysMap" + investmentMaintainedDaysMap);
|
| 124 |
|
124 |
|
| - |
|
125 |
// Batch fetch investments for all fofoStores at once (performance optimization)
|
| 125 |
Map<Integer, PartnerDailyInvestment> investmentMap = fofoStores.stream().map(x -> {
|
126 |
Map<Integer, PartnerDailyInvestment> investmentMap;
|
| - |
|
127 |
try {
|
| - |
|
128 |
investmentMap = partnerInvestmentService.getInvestmentsForFofoStores(fofoStores);
|
| - |
|
129 |
} catch (Exception e) {
|
| - |
|
130 |
LOGGER.error("Error fetching investments in batch, falling back to individual calls", e);
|
| - |
|
131 |
investmentMap = fofoStores.stream().map(x -> {
|
| 126 |
try {
|
132 |
try {
|
| 127 |
return partnerInvestmentService.getInvestment(x.getId(), 0);
|
133 |
return partnerInvestmentService.getInvestment(x.getId(), 0);
|
| 128 |
} catch (Exception e) {
|
134 |
} catch (Exception ex) {
|
| 129 |
LOGGER.info("Could not get invetment summary for {}", x);
|
135 |
LOGGER.info("Could not get investment summary for {}", x);
|
| 130 |
return new PartnerDailyInvestment();
|
136 |
return new PartnerDailyInvestment();
|
| 131 |
}
|
137 |
}
|
| 132 |
}).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
138 |
}).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| - |
|
139 |
}
|
| 133 |
|
140 |
|
| 134 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMappingByCategoryIds(Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_RBM), true);
|
141 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMappingByCategoryIds(Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_RBM), true);
|
| 135 |
Map<String, AuthUser> authUserMap = authRepository.selectAll().stream().filter(x -> storeGuyMap.keySet().contains(x.getEmailId())).collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
142 |
Map<String, AuthUser> authUserMap = authRepository.selectAll().stream().filter(x -> storeGuyMap.keySet().contains(x.getEmailId())).collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
| 136 |
Map<Integer, Set<AuthUser>> partnerRbmsMap = new HashMap<>();
|
143 |
Map<Integer, Set<AuthUser>> partnerRbmsMap = new HashMap<>();
|
| 137 |
for (Map.Entry<String, Set<Integer>> storeGuySetEntry : storeGuyMap.entrySet()) {
|
144 |
for (Map.Entry<String, Set<Integer>> storeGuySetEntry : storeGuyMap.entrySet()) {
|
| Line 156... |
Line 163... |
| 156 |
Map<Integer, Long> invalidHygieneCountMap = hygieneDataRepository.selectHygieneCountByFofoIds(fofoIds, false, hygieneStartDate, hygieneEndDate);
|
163 |
Map<Integer, Long> invalidHygieneCountMap = hygieneDataRepository.selectHygieneCountByFofoIds(fofoIds, false, hygieneStartDate, hygieneEndDate);
|
| 157 |
|
164 |
|
| 158 |
// Bulk fetch partner types to avoid N+1 queries
|
165 |
// Bulk fetch partner types to avoid N+1 queries
|
| 159 |
Map<Integer, PartnerType> partnerTypeMap = partnerTypeChangeService.getTypesForFofoIds(new ArrayList<>(fofoIds), LocalDate.now());
|
166 |
Map<Integer, PartnerType> partnerTypeMap = partnerTypeChangeService.getTypesForFofoIds(new ArrayList<>(fofoIds), LocalDate.now());
|
| 160 |
|
167 |
|
| - |
|
168 |
// Batch fetch auth user escalations for all fofoIds at once (performance optimization)
|
| - |
|
169 |
Map<Integer, Map<EscalationType, AuthUser>> authUserEscalationMap = csService.getAuthUserAndEsclationByPartnerIds(fofoIds);
|
| - |
|
170 |
|
| 161 |
for (FofoStore store : fofoStores) {
|
171 |
for (FofoStore store : fofoStores) {
|
| 162 |
int fofoId = store.getId();
|
172 |
int fofoId = store.getId();
|
| 163 |
|
173 |
|
| 164 |
// Use batch-fetched hygiene counts instead of N+1 queries
|
174 |
// Use batch-fetched hygiene counts instead of N+1 queries
|
| 165 |
int hygieneCount = validHygieneCountMap.getOrDefault(fofoId, 0L).intValue();
|
175 |
int hygieneCount = validHygieneCountMap.getOrDefault(fofoId, 0L).intValue();
|
| 166 |
int invalidHygieneCount = invalidHygieneCountMap.getOrDefault(fofoId, 0L).intValue();
|
176 |
int invalidHygieneCount = invalidHygieneCountMap.getOrDefault(fofoId, 0L).intValue();
|
| 167 |
int totalHygieneCount = hygieneCount + invalidHygieneCount;
|
177 |
int totalHygieneCount = hygieneCount + invalidHygieneCount;
|
| 168 |
PartnerType partnerType = partnerTypeMap.get(fofoId);
|
178 |
PartnerType partnerType = partnerTypeMap.get(fofoId);
|
| 169 |
|
179 |
|
| 170 |
Map<EscalationType, AuthUser> authuserEsclationTypeMap = csService
|
180 |
// Use batch-fetched auth user escalations instead of N+1 queries
|
| 171 |
.getAuthUserAndEsclationByPartnerId(fofoId);
|
181 |
Map<EscalationType, AuthUser> authuserEsclationTypeMap = authUserEscalationMap.getOrDefault(fofoId, new HashMap<>());
|
| 172 |
PartnerDetailModel pm = new PartnerDetailModel();
|
182 |
PartnerDetailModel pm = new PartnerDetailModel();
|
| 173 |
pm.setFofoId(fofoId);
|
183 |
pm.setFofoId(fofoId);
|
| 174 |
pm.setLmtd(lmtdSale.get(fofoId) == null ? 0 : lmtdSale.get(fofoId).intValue());
|
184 |
pm.setLmtd(lmtdSale.get(fofoId) == null ? 0 : lmtdSale.get(fofoId).intValue());
|
| 175 |
pm.setMtd(mtdSale.get(fofoId) == null ? 0 : mtdSale.get(fofoId).intValue());
|
185 |
pm.setMtd(mtdSale.get(fofoId) == null ? 0 : mtdSale.get(fofoId).intValue());
|
| 176 |
pm.setLms(lmsSale.get(fofoId) == null ? 0 : lmsSale.get(fofoId).intValue());
|
186 |
pm.setLms(lmsSale.get(fofoId) == null ? 0 : lmsSale.get(fofoId).intValue());
|