Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVA-3474 Remove duplicate accessions when fetching from db #81

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 tests of same accessions with different hashes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// create and save accessions in db (100 to 124) - save 2 tests of same accessions with different hashes
// create and save accessions in db (100 to 124) - save 2 sets of same accessions with different hashes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected

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
Loading