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

reduce dataset id collisions #2707

Merged
merged 2 commits into from Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion study/src/org/labkey/study/assay/StudyPublishManager.java
Expand Up @@ -873,7 +873,19 @@ public DatasetDefinition createDataset(User user, @NotNull DatasetDefinition.Bui

// auto generate a dataset ID
if (null == builder.getDatasetId())
builder.setDatasetId(new SqlSelector(schema, "SELECT MAX(n) + 1 AS id FROM (SELECT Max(datasetid) AS n FROM study.dataset WHERE container=? UNION SELECT ? As n) x", study.getContainer().getId(), MIN_ASSAY_ID).getObject(Integer.class));
{
int id = study.isDataspaceStudy() ? 10000 : MIN_ASSAY_ID;
Integer mx = new SqlSelector(schema, "SELECT MAX(datasetid) FROM study.dataset WHERE container=?", study.getContainer().getId()).getObject(Integer.class);
if (null != mx)
id = Math.max(id,mx);
if (study.isDataspaceStudy())
{
mx = new SqlSelector(schema, "SELECT MAX(datasetid) FROM study.dataset WHERE container=?", study.getContainer().getProject().getId()).getObject(Integer.class);
if (null != mx)
id = Math.max(id, mx);
}
builder.setDatasetId(id+1);
}

DatasetDefinition dsd = builder.build();
if (dsd.getUseTimeKeyField() && (dsd.isDemographicData() || dsd.getKeyPropertyName() != null))
Expand Down