Skip to content

Commit d43576e

Browse files
Move demographic recache to post commit task (#781)
* Make demographic recache a post commit task * Remove delay from job as recache is now running after the transaction commits * Add some test helpers
1 parent 4130353 commit d43576e

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

ehr/src/org/labkey/ehr/demographics/EHRDemographicsServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ private void asyncCache(final Container c, final List<String> ids)
472472
{
473473
_log.error("EHRDemographicsServiceImpl encountered a deadlock", e);
474474
}
475-
}, 5000);
475+
});
476476
}
477477

478478
/**

ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.labkey.api.data.ContainerManager;
3232
import org.labkey.api.data.ConvertHelper;
3333
import org.labkey.api.data.DbSchema;
34+
import org.labkey.api.data.DbScope;
3435
import org.labkey.api.data.Results;
3536
import org.labkey.api.data.ResultsImpl;
3637
import org.labkey.api.data.RuntimeSQLException;
@@ -871,7 +872,17 @@ public void createDemographicsRecord(String id, Map<String, Object> props,
871872
// inserted a row into study.participant, which means that calculated lookup values like the animal's current
872873
// age won't resolve until AFTER the call to insertRows() has completed. Thus, refresh the cache for this new
873874
// animal an extra time. See ticket 44283.
874-
EHRDemographicsServiceImpl.get().recacheRecords(getContainer(), Collections.singletonList(id));
875+
try (DbScope.Transaction transaction = StudyService.get().getDatasetSchema().getScope().ensureTransaction())
876+
{
877+
// Add post commit task to run provider update in another thread once this transaction is complete.
878+
transaction.addCommitTask(() ->
879+
{
880+
// Update provider in another thread
881+
EHRDemographicsServiceImpl.get().recacheRecords(getContainer(), Collections.singletonList(id));
882+
}, DbScope.CommitTaskOption.POSTCOMMIT);
883+
884+
transaction.commit();
885+
}
875886
}
876887

877888
public void updateDemographicsRecord(List<Map<String, Object>> updatedRows) throws QueryUpdateServiceException, SQLException, BatchValidationException, InvalidKeyException

ehr/test/src/org/labkey/test/tests/ehr/AbstractEHRTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ protected void createTestSubjects() throws Exception
298298
insertCommand = getApiHelper().prepareInsertCommand("study", "Assignment", "lsid", fields, data);
299299
getApiHelper().deleteAllRecords("study", "Assignment", new Filter("Id", StringUtils.join(SUBJECTS, ";"), Filter.Operator.IN));
300300
getApiHelper().doSaveRows(DATA_ADMIN.getEmail(), insertCommand, getExtraContext());
301+
302+
primeCaches();
301303
}
302304

303305
@Override
@@ -756,6 +758,12 @@ private void setEhrUserPasswords()
756758
setInitialPassword(REQUEST_ADMIN.getEmail());
757759
}
758760

761+
protected void validateDemographicsCache()
762+
{
763+
beginAt(WebTestHelper.buildURL("ehr", getContainerPath(), "cacheLivingAnimals", Map.of("validateOnly", "true")));
764+
waitAndClick(WAIT_FOR_JAVASCRIPT, Locator.lkButton("OK"), WAIT_FOR_PAGE * 4);
765+
}
766+
759767
protected static final ArrayList<Permission> allowedActions = new ArrayList<>()
760768
{
761769
{

ehr/test/src/org/labkey/test/util/ehr/EHRTestHelper.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.labkey.test.BaseWebDriverTest;
2121
import org.labkey.test.Locator;
2222
import org.labkey.test.Locators;
23+
import org.labkey.test.components.ext4.Window;
2324
import org.labkey.test.pages.ehr.ParticipantViewPage;
2425
import org.labkey.test.tests.ehr.AbstractEHRTest;
2526
import org.labkey.test.util.Ext4Helper;
@@ -246,6 +247,26 @@ public void discardForm()
246247
_test.waitForElement(Locator.tagWithText("a", "Enter New Data"));
247248
}
248249

250+
public void submitFinalTaskForm()
251+
{
252+
Locator submitFinalBtn = Locator.linkWithText("Submit Final");
253+
_test.shortWait().until(ExpectedConditions.elementToBeClickable(submitFinalBtn));
254+
Window<?> msgWindow;
255+
try
256+
{
257+
submitFinalBtn.findElement(_test.getDriver()).click();
258+
msgWindow = new Window.WindowFinder(_test.getDriver()).withTitleContaining("Finalize").waitFor();
259+
}
260+
catch (NoSuchElementException e)
261+
{
262+
//retry
263+
_test.sleep(500);
264+
submitFinalBtn.findElement(_test.getDriver()).click();
265+
msgWindow = new Window.WindowFinder(_test.getDriver()).withTitleContaining("Finalize").waitFor();
266+
}
267+
msgWindow.clickButton("Yes");
268+
}
269+
249270
public void verifyAllReportTabs(ParticipantViewPage participantView)
250271
{
251272
verifyReportTabs(participantView, Collections.emptyMap());

0 commit comments

Comments
 (0)