Skip to content

Commit

Permalink
Merge pull request #81 from nitin-ebi/recover-state
Browse files Browse the repository at this point in the history
EVA-3474  Remove duplicate accessions when fetching from db
  • Loading branch information
nitin-ebi authored Jan 12, 2024
2 parents fc07308 + b13dd5e commit 9966bc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -62,18 +64,18 @@ public BasicSpringDataRepositoryMonotonicDatabaseService(

@Override
public long[] getAccessionsInRanges(Collection<MonotonicRange> ranges) {
List<Long> accessionsInDB = new ArrayList<>();
Set<Long> accessionsInDB = new HashSet<>();
for (MonotonicRange potentiallyBigRange : ranges) {
for (MonotonicRange range : ensureRangeMaxSize(potentiallyBigRange, MAX_RANGE_SIZE)) {
List<AccessionProjection<Long>> accessionsInRange =
repository.findByAccessionGreaterThanEqualAndAccessionLessThanEqual(range.getStart(),
range.getEnd());

accessionsInDB.addAll(accessionsInRange.stream().map(ap -> ap.getAccession()).collect(Collectors.toList()));
accessionsInDB.addAll(accessionsInRange.stream().map(ap -> ap.getAccession()).collect(Collectors.toSet()));
}
}

long[] accessionArray = accessionsInDB.stream().mapToLong(l -> l).toArray();
long[] accessionArray = accessionsInDB.stream().mapToLong(l -> l).sorted().toArray();
return accessionArray;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,19 @@ public void testRecoverState() {

assertEquals(3, contiguousIdBlockService.getUncompletedBlocksByCategoryIdAndApplicationInstanceIdOrderByEndAsc(categoryId, instanceId2).size());

// create and save accessions in db (100 to 124)
List<AccessionWrapper<TestModel, String, Long>> accessions = LongStream.range(100l, 125l)
// create and save accessions in db (100 to 124) - save 2 sets of same accessions with different hashes
List<AccessionWrapper<TestModel, String, Long>> accessionsSet1 = LongStream.range(100l, 125l)
.boxed()
.map(longAcc -> new AccessionWrapper<>(longAcc, "hash" + longAcc, TestModel.of("test-obj-" + longAcc)))
.map(longAcc -> new AccessionWrapper<>(longAcc, "hash-1" + longAcc, TestModel.of("test-obj-1-" + longAcc)))
.collect(Collectors.toList());
databaseService.save(accessions);
List<AccessionWrapper<TestModel, String, Long>> accessionsSet2 = LongStream.range(100l, 125l)
.boxed()
.map(longAcc -> new AccessionWrapper<>(longAcc, "hash-2" + longAcc, TestModel.of("test-obj-2-" + longAcc)))
.collect(Collectors.toList());
databaseService.save(accessionsSet1);
databaseService.save(accessionsSet2);

// run recover blocks
// run recover state
MonotonicAccessionGenerator generator = getGenerator(categoryId, instanceId2);

// As we have already saved accessions in db from 100 to 124, the status should be
Expand Down

0 comments on commit 9966bc2

Please sign in to comment.