From 7afa953b747f9ab7a8598df5f2191ca5f83c7f49 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Tue, 6 Jun 2023 13:16:02 -0700 Subject: [PATCH] Speed up clearing LastIndexed on lists (#4490) --- list/src/org/labkey/list/model/ListManager.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/list/src/org/labkey/list/model/ListManager.java b/list/src/org/labkey/list/model/ListManager.java index baef37be723..d40b710ea2e 100644 --- a/list/src/org/labkey/list/model/ListManager.java +++ b/list/src/org/labkey/list/model/ListManager.java @@ -1101,18 +1101,31 @@ public void indexDeleted() // Now clear LastIndexed column of every underlying list table, which addresses the "index each list item as a separate document" case. See #28748. new TableSelector(getListMetadataTable()).forEach(ListDef.class, listDef -> { + clearLastIndexed(scope, listSchemaName, listDef); + }); + } + + private void clearLastIndexed(DbScope scope, String listSchemaName, ListDef listDef) + { + // Clear LastIndexed column only for lists that are set to index each item, Issue 47998 + if (listDef.getEachItemIndex()) + { ListDefinition list = new ListDefinitionImpl(listDef); Domain domain = list.getDomain(); if (null != domain && null != domain.getStorageTableName()) + { + LOG.info("List " + listDef.getContainerPath() + " - " + listDef.getName() + ": Set to index each item, so clearing last indexed"); clearLastIndexed(scope, listSchemaName + "." + domain.getStorageTableName()); - }); + } + } } private void clearLastIndexed(DbScope scope, String selectName) { try { - new SqlExecutor(scope).execute("UPDATE " + selectName + " SET LastIndexed = NULL"); + // Yes, that WHERE clause is intentional and makes a big performance improvement in some cases + new SqlExecutor(scope).execute("UPDATE " + selectName + " SET LastIndexed = NULL WHERE LastIndexed IS NOT NULL"); } catch (Exception e) {