From f315a22c4f2cb874c794851f968e7a1dc8201a6c Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Fri, 31 May 2019 15:35:00 -0700 Subject: [PATCH] Fix a bunch of TargetedMS tests. TargetedMSTable wasn't actually immutable, which made it quite unsafe to cache. Now it is, and we can use a ContainerFilter (already handled via the caching code) to control the lookup behavior to get the same optimized query generated. --- src/org/labkey/targetedms/query/TargetedMSForeignKey.java | 7 ++++--- src/org/labkey/targetedms/query/TargetedMSTable.java | 7 +------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/org/labkey/targetedms/query/TargetedMSForeignKey.java b/src/org/labkey/targetedms/query/TargetedMSForeignKey.java index 974fa7a9c..1804d7d0e 100644 --- a/src/org/labkey/targetedms/query/TargetedMSForeignKey.java +++ b/src/org/labkey/targetedms/query/TargetedMSForeignKey.java @@ -38,8 +38,9 @@ public TargetedMSForeignKey(TargetedMSSchema schema, String tableName, Container @Override public TableInfo getLookupTableInfo() { - TableInfo table = _schema.getTable(_tableName); - ((TargetedMSTable)table).setNeedsContainerWhereClause(false); - return table; + // Avoid applying a container filter on lookups. The import process should be only creating FKs to data + // in the same container. Thus, we can rely on the outer query doing the proper filtering and avoid + // what can be expensive multi-table joins to get to a table that has the Container column we need + return _schema.getTable(_tableName, ContainerFilter.EVERYTHING); } } diff --git a/src/org/labkey/targetedms/query/TargetedMSTable.java b/src/org/labkey/targetedms/query/TargetedMSTable.java index f9d0c4e3a..7c6a0c75f 100644 --- a/src/org/labkey/targetedms/query/TargetedMSTable.java +++ b/src/org/labkey/targetedms/query/TargetedMSTable.java @@ -89,11 +89,6 @@ protected void applyContainerFilter(ContainerFilter filter) // Don't apply the container filter normally, let us apply it in our wrapper around the normally generated SQL } - public void setNeedsContainerWhereClause(boolean needsContainerWhereClause) - { - _needsContainerWhereClause = needsContainerWhereClause; - } - @Override @NotNull public SQLFragment getFromSQL(String alias) @@ -102,7 +97,7 @@ public SQLFragment getFromSQL(String alias) sql.append(super.getFromSQL("X")); sql.append(" "); - if (_needsContainerWhereClause || _containerTableFilter != null) + if (getContainerFilter() != ContainerFilter.EVERYTHING || _containerTableFilter != null) { sql.append(_joinType != null ? _joinType.getSQL() : "");