how to make Pageable query able to fetch all the rows

72 views Asked by At

Unable to fetch and update all the rows having source_channel as SourceChannels.DRIVER_REFERRAL_CHANNEL.

batchSize = 2
Page<Lead> driverReferralLeads = repository.findByChannelAndCreatedAtIsLessThanAndDriverIdIsNullAndStatusIn(SourceChannels.DRIVER_REFERRAL_CHANNEL, expiryDate, statusForExpiring, PageRequest.of(0, batchSize));
List<Lead> driverReferralLeadsList = driverReferralLeads.getContent();
LOGGER.info("{} phoneNumbers: {}", SourceChannels.DRIVER_REFERRAL_CHANNEL, driverReferralLeadsList.stream().map(Lead::getPhone).toArray()); // todo to be removed
service.expireLeads(SourceChannels.DRIVER_REFERRAL_CHANNEL, driverReferralLeadsList, expiryDate);
int driverReferralLeadsIteration = 0; // todo to be removed
while (driverReferralLeads.hasNext()) {
    LOGGER.info("{} iteration [{}].", SourceChannels.DRIVER_REFERRAL_CHANNEL, driverReferralLeadsIteration); // todo to be removed
    driverReferralLeads = repository.findByChannelAndCreatedAtIsLessThanAndDriverIdIsNullAndStatusIn(SourceChannels.DRIVER_REFERRAL_CHANNEL, expiryDate, statusForExpiring, driverReferralLeads.nextPageable());
    List<Lead> driverReferralLeadsNextList = driverReferralLeads.getContent();
    LOGGER.info("{} iteration [{}]. phoneNumbers: {}", SourceChannels.DRIVER_REFERRAL_CHANNEL, driverReferralLeadsIteration, driverReferralLeadsNextList.stream().map(Lead::getPhone).toArray()); // todo to be removed
    cartHeroService.expireLeads(SourceChannels.DRIVER_REFERRAL_CHANNEL, driverReferralLeadsNextList, expiryDate);
    driverReferralLeadsIteration++; // todo to be removed
}
LOGGER.info("{} Expired [{}] Leads.", LEAD_EXPIRY_LOGGER, SourceChannels.DRIVER_REFERRAL_CHANNEL);

6 records are there and it always fetches and updates 4. 2nd iteration of the while loop is not able to fetch anything but still goes inside the loop(have logs to prove).

log: 

Driver Referral iteration [0]. phoneNumbers: [1122334455, 1123455551]

Driver Referral iteration [1]. phoneNumbers: []
0

There are 0 answers