Skip to content

Commit 8cf1c92

Browse files
Switch from direct ClientDependency references to Suppliers (#25)
Issue 40118: Client dependencies are cached too aggressively
1 parent 032e61b commit 8cf1c92

File tree

4 files changed

+61
-31
lines changed

4 files changed

+61
-31
lines changed

LDK/src/org/labkey/ldk/query/DefaultTableCustomizer.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.ArrayList;
5050
import java.util.Arrays;
5151
import java.util.Collection;
52+
import java.util.Collections;
5253
import java.util.HashMap;
5354
import java.util.LinkedHashSet;
5455
import java.util.List;
@@ -71,14 +72,15 @@ public class DefaultTableCustomizer implements TableCustomizer
7172

7273
public DefaultTableCustomizer()
7374
{
74-
this(new ArrayListValuedHashMap());
75+
this(new ArrayListValuedHashMap<>());
7576
}
7677

77-
public DefaultTableCustomizer(MultiValuedMap props)
78+
public DefaultTableCustomizer(MultiValuedMap<String, String> props)
7879
{
7980
_settings = new Settings(props);
8081
}
8182

83+
@Override
8284
public void customize(TableInfo table)
8385
{
8486
if (table instanceof SchemaTableInfo)
@@ -305,15 +307,12 @@ public static void customizeButtonBar(AbstractTableInfo ti, List<ButtonConfigFac
305307
String[] existingScripts = cfg.getScriptIncludes();
306308
if (existingScripts != null)
307309
{
308-
for (String s : existingScripts)
309-
{
310-
scripts.add(s);
311-
}
310+
Collections.addAll(scripts, existingScripts);
312311
}
313312

314313
boolean hasMoreActions = configureMoreActionsBtn(ti, buttons, cfg, scripts);
315314

316-
cfg.setScriptIncludes(scripts.toArray(new String[scripts.size()]));
315+
cfg.setScriptIncludes(scripts.toArray(new String[0]));
317316
if (hasMoreActions)
318317
cfg.setAlwaysShowRecordSelectors(true);
319318

@@ -400,12 +399,12 @@ private static boolean configureMoreActionsBtn(TableInfo ti, List<ButtonConfigFa
400399
cfg.setItems(existingBtns);
401400
}
402401

403-
List<NavTree> menuItems = new ArrayList<NavTree>();
402+
List<NavTree> menuItems = new ArrayList<>();
404403
if (moreActionsBtn.getMenuItems() != null)
405404
menuItems.addAll(moreActionsBtn.getMenuItems());
406405

407406
//create map of existing item names
408-
Map<String, NavTree> btnNameMap = new HashMap<String, NavTree>();
407+
Map<String, NavTree> btnNameMap = new HashMap<>();
409408
for (NavTree item : menuItems)
410409
{
411410
btnNameMap.put(item.getText(), item);
@@ -419,7 +418,7 @@ private static boolean configureMoreActionsBtn(TableInfo ti, List<ButtonConfigFa
419418
btnNameMap.put(newButton.getText(), newButton);
420419
menuItems.add(newButton);
421420

422-
for (ClientDependency cd : fact.getClientDependencies(ti.getUserSchema().getContainer(), ti.getUserSchema().getUser()))
421+
for (ClientDependency cd : ClientDependency.getClientDependencySet(fact.getClientDependencies(ti.getUserSchema().getContainer(), ti.getUserSchema().getUser())))
423422
{
424423
scripts.add(cd.getScriptString());
425424
}

laboratory/api-src/org/labkey/api/laboratory/button/ChangeAssayResultStatusBtn.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.labkey.api.security.permissions.UpdatePermission;
2222
import org.labkey.api.view.template.ClientDependency;
2323

24+
import java.util.Arrays;
25+
2426
/**
2527
* User: bimber
2628
* Date: 9/8/13
@@ -36,7 +38,7 @@ public ChangeAssayResultStatusBtn(Module owner)
3638
public ChangeAssayResultStatusBtn(Module owner, String label)
3739
{
3840
super(owner, label, "Laboratory.window.ChangeAssayResultStatusWindow.buttonHandler(dataRegionName);");
39-
setClientDependencies(ClientDependency.fromModuleName("laboratory"), ClientDependency.fromPath("laboratory/window/ChangeAssayResultStatusWindow.js"));
41+
setClientDependencies(Arrays.asList(ClientDependency.supplierFromModuleName("laboratory"), ClientDependency.supplierFromPath("laboratory/window/ChangeAssayResultStatusWindow.js")));
4042
}
4143

4244
public boolean isAvailable(TableInfo ti)

laboratory/src/org/labkey/laboratory/LaboratoryModule.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353
import java.util.Arrays;
5454
import java.util.Collection;
5555
import java.util.HashMap;
56-
import java.util.LinkedHashSet;
56+
import java.util.LinkedList;
57+
import java.util.List;
5758
import java.util.Map;
5859
import java.util.Set;
60+
import java.util.function.Supplier;
5961

6062
/**
6163
* User: bimber
@@ -173,17 +175,17 @@ protected void doStartupAfterSpringConfig(ModuleContext moduleContext)
173175
LDKService.get().registerContainerScopedTable(SCHEMA_NAME, LaboratorySchema.TABLE_SUBJECTS, "subjectname");
174176

175177
SimpleButtonConfigFactory btn1 = new SimpleButtonConfigFactory(this, "Mark Removed", "Laboratory.buttonHandlers.markSamplesRemoved(dataRegionName, arguments[0])");
176-
btn1.setClientDependencies(ClientDependency.fromModuleName("laboratory"));
178+
btn1.setClientDependencies(ClientDependency.supplierFromModuleName("laboratory"));
177179
btn1.setPermission(UpdatePermission.class);
178180
LDKService.get().registerQueryButton(btn1, LaboratoryModule.SCHEMA_NAME, LaboratorySchema.TABLE_SAMPLES);
179181

180182
SimpleButtonConfigFactory btn2 = new SimpleButtonConfigFactory(this, "Duplicate/Derive Samples", "Laboratory.buttonHandlers.deriveSamples(dataRegionName, arguments[0])");
181-
btn2.setClientDependencies(ClientDependency.fromModuleName("laboratory"));
183+
btn2.setClientDependencies(ClientDependency.supplierFromModuleName("laboratory"));
182184
btn2.setPermission(UpdatePermission.class);
183185
LDKService.get().registerQueryButton(btn2, LaboratoryModule.SCHEMA_NAME, LaboratorySchema.TABLE_SAMPLES);
184186

185187
SimpleButtonConfigFactory btn4 = new SimpleButtonConfigFactory(this, "Append Comment", "Laboratory.buttonHandlers.appendCommentToSamples(dataRegionName, arguments[0])");
186-
btn4.setClientDependencies(ClientDependency.fromModuleName("laboratory"));
188+
btn4.setClientDependencies(ClientDependency.supplierFromModuleName("laboratory"));
187189
btn4.setPermission(UpdatePermission.class);
188190
LDKService.get().registerQueryButton(btn4, LaboratoryModule.SCHEMA_NAME, LaboratorySchema.TABLE_SAMPLES);
189191

@@ -212,11 +214,11 @@ public Set<String> getSchemaNames()
212214

213215
@NotNull
214216
@Override
215-
public LinkedHashSet<ClientDependency> getClientDependencies(Container c)
217+
public List<Supplier<ClientDependency>> getClientDependencies(Container c)
216218
{
217219
// allow other modules to register with EHR service, and include their dependencies automatically
218220
// whenever laboratory context is requested
219-
LinkedHashSet<ClientDependency> ret = new LinkedHashSet<>();
221+
List<Supplier<ClientDependency>> ret = new LinkedList<>();
220222
ret.addAll(super.getClientDependencies(c));
221223
ret.addAll(LaboratoryService.get().getRegisteredClientDependencies(c));
222224

0 commit comments

Comments
 (0)