private <T> void doDelete(String theDescriptor, Supplier<Slice<T>> theLoader, Supplier<Integer> theCounter, JpaRepository<T, ?> theDao) { int count; ourLog.info(" * Deleting {}", theDescriptor); int totalCount = theCounter.get(); StopWatch sw = new StopWatch(); count = 0; while (true) { Slice<T> link = theLoader.get(); if (link.hasContent() == false) { break; } TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); txTemplate.execute(t -> { theDao.deleteInBatch(link); return null; }); count += link.getNumberOfElements(); ourLog.info(" * {} {} deleted - {}/sec - ETA: {}", count, theDescriptor, sw.formatThroughput(count, TimeUnit.SECONDS), sw.getEstimatedTimeRemaining(count, totalCount)); } theDao.flush(); }
private void deleteSearch(final Long theSearchPid) { mySearchDao.findById(theSearchPid).ifPresent(searchToDelete -> { mySearchIncludeDao.deleteForSearch(searchToDelete.getId()); /* * Note, we're only deleting up to 500 results in an individual search here. This * is to prevent really long running transactions in cases where there are * huge searches with tons of results in them. By the time we've gotten here * we have marked the parent Search entity as deleted, so it's not such a * huge deal to be only partially deleting search results. They'll get deleted * eventually */ int max = ourMaximumResultsToDeleteInOnePass; Slice<Long> resultPids = mySearchResultDao.findForSearch(PageRequest.of(0, max), searchToDelete.getId()); if (resultPids.hasContent()) { List<List<Long>> partitions = Lists.partition(resultPids.getContent(), ourMaximumResultsToDeleteInOneStatement); for (List<Long> nextPartition : partitions) { mySearchResultDao.deleteByIds(nextPartition); } } // Only delete if we don't have results left in this search if (resultPids.getNumberOfElements() < max) { ourLog.info("Deleting search {}/{} - Created[{}] -- Last returned[{}]", searchToDelete.getId(), searchToDelete.getUuid(), new InstantType(searchToDelete.getCreated()), new InstantType(searchToDelete.getSearchLastReturned())); mySearchDao.deleteByPid(searchToDelete.getId()); } else { ourLog.info("Purged {} search results for deleted search {}/{}", resultPids.getSize(), searchToDelete.getId(), searchToDelete.getUuid()); } }); }
do { idProjections = this.jobRepository.findByCreatedBefore(date, page); if (idProjections.hasContent()) { final List<Long> ids = idProjections .getContent()
private <T> void doDelete(String theDescriptor, Supplier<Slice<T>> theLoader, Supplier<Integer> theCounter, JpaRepository<T, ?> theDao) { int count; ourLog.info(" * Deleting {}", theDescriptor); int totalCount = theCounter.get(); StopWatch sw = new StopWatch(); count = 0; while (true) { Slice<T> link = theLoader.get(); if (link.hasContent() == false) { break; } TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); txTemplate.execute(t -> { theDao.deleteInBatch(link); return null; }); count += link.getNumberOfElements(); ourLog.info(" * {} {} deleted - {}/sec - ETA: {}", count, theDescriptor, sw.formatThroughput(count, TimeUnit.SECONDS), sw.getEstimatedTimeRemaining(count, totalCount)); } theDao.flush(); }
needsToWarn = null; } while (needsToWarn != null && needsToWarn.hasContent()); needsToDeactivate = null; } while (needsToDeactivate != null && needsToDeactivate.hasContent()); needsToDeactivate = null; } while (needsToDeactivate != null && needsToDeactivate.hasContent()); logger.info("Inactivity check finished. Sent warning to {} needs, deactivated {} needs", warned.get(), deactivated.get()); } catch (Throwable t) {
private void deleteSearch(final Long theSearchPid) { mySearchDao.findById(theSearchPid).ifPresent(searchToDelete -> { mySearchIncludeDao.deleteForSearch(searchToDelete.getId()); /* * Note, we're only deleting up to 500 results in an individual search here. This * is to prevent really long running transactions in cases where there are * huge searches with tons of results in them. By the time we've gotten here * we have marked the parent Search entity as deleted, so it's not such a * huge deal to be only partially deleting search results. They'll get deleted * eventually */ int max = ourMaximumResultsToDeleteInOnePass; Slice<Long> resultPids = mySearchResultDao.findForSearch(PageRequest.of(0, max), searchToDelete.getId()); if (resultPids.hasContent()) { List<List<Long>> partitions = Lists.partition(resultPids.getContent(), ourMaximumResultsToDeleteInOneStatement); for (List<Long> nextPartition : partitions) { mySearchResultDao.deleteByIds(nextPartition); } } // Only delete if we don't have results left in this search if (resultPids.getNumberOfElements() < max) { ourLog.debug("Deleting search {}/{} - Created[{}] -- Last returned[{}]", searchToDelete.getId(), searchToDelete.getUuid(), new InstantType(searchToDelete.getCreated()), new InstantType(searchToDelete.getSearchLastReturned())); mySearchDao.deleteByPid(searchToDelete.getId()); } else { ourLog.debug("Purged {} search results for deleted search {}/{}", resultPids.getSize(), searchToDelete.getId(), searchToDelete.getUuid()); } }); }
messageEventRepository.findByParentURIFetchDatasetEagerly(connectionUri, new PageRequest(0, 1, new Sort(Sort .Direction.DESC, "creationDate"))); if (latestEvents.hasContent()) { MessageEventPlaceholder event = latestEvents.getContent().get(0);