Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 17 additions & 2 deletions api/src/org/labkey/api/assay/AbstractAssayTsvDataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;
import static org.labkey.api.assay.AssayRunUploadContext.ReImportOption.MERGE_DATA;
Expand Down Expand Up @@ -1084,13 +1085,27 @@ else if (validatorMap.containsKey(pd))

if (plateId != null && wellLocation != null)
{
Map<String, Long> wellSampleCache = plateWellCache.computeIfAbsent(plateId, (id) -> AssayPlateMetadataService.get().getWellLocationToSampleIdMap(container, user, plateId));
boolean loadMaterialsCache = !plateWellCache.containsKey(plateId);
Map<String, Long> wellSampleCache = plateWellCache.computeIfAbsent(plateId, (id) -> AssayPlateMetadataService.get().getWellLocationToSampleIdMap(plateId));

// If we had to load the wellSampleCache we should also preload the ExpMaterials into the
// materialCache, so we don't need to fetch them with individual queries. This has a large
// impact on performance.
if (loadMaterialsCache)
{
Set<Long> samplesToFetch = wellSampleCache.values().stream()
.filter(id -> !materialCache.containsKey(id))
.collect(Collectors.toSet());

for (ExpMaterial m : exp.getExpMaterials(samplesToFetch))
materialCache.put(m.getRowId(), m);
}
sampleId = wellSampleCache.get(wellLocation);
}

if (sampleId != null)
{
material = materialCache.computeIfAbsent(sampleId, (id) -> exp.getExpMaterial(id, containerFilter));
material = materialCache.get(sampleId);
}

if (material != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void applyHitSelectionCriteria(
/**
* Returns a Map of Well Location to Sample RowID for a given Plate ID.
*/
Map<String, Long> getWellLocationToSampleIdMap(Container container, User user, Long plateId);
Map<String, Long> getWellLocationToSampleIdMap(Long plateId);

boolean isWellLookup(ColumnInfo col);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1518,14 +1518,23 @@ public String format(FieldKey fieldKey)
return new PlateSchema(querySchema, contextualRoles);
}

record WellSampleData(Long sampleId, Integer row, Integer col) {}

@Override
public Map<String, Long> getWellLocationToSampleIdMap(Container container, User user, Long plateId)
public Map<String, Long> getWellLocationToSampleIdMap(Long plateId)
{
// Note: this method intentionally does not use PlateManager.get().getWellData, by selecting only the columns
// we need there is a small but measurable performance boost when importing plate assay data
SimpleFilter filter = new SimpleFilter(WellTable.Column.PlateId.fieldKey(), plateId);
Set<String> columns = Set.of(WellTable.Column.SampleID.name(), WellTable.Column.Row.name(), WellTable.Column.Col.name());
List<WellSampleData> wells = new TableSelector(AssayDbSchema.getInstance().getTableInfoWell(), columns, filter, null).getArrayList(WellSampleData.class);
Map<String, Long> wellLocationToSampleIdMap = new HashMap<>();
List<WellData> wellData = PlateManager.get().getWellData(container, user, plateId, true, false);

for (WellData data : wellData)
wellLocationToSampleIdMap.put(data.getPosition(), data.getSampleId());
for (WellSampleData well : wells)
{
PositionImpl pos = new PositionImpl(null, well.row, well.col);
wellLocationToSampleIdMap.put(pos.getDescription(), well.sampleId);
}

return wellLocationToSampleIdMap;
}
Expand Down