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()); } }); }
/** * Returns the {@link Pageable} that's been used to request the current {@link Slice}. * * @return * @since 2.0 */ default Pageable getPageable() { return PageRequest.of(getNumber(), getSize(), getSort()); }
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()); } }); }