From 7c4158b5f9d08007d96989d6da1166dcfc3bd846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olov=20Ylinenp=C3=A4=C3=A4?= Date: Mon, 25 Nov 2024 14:49:00 +0100 Subject: [PATCH] fix(emm): Don't include deleted docs in dump --- emm/src/main/java/whelk/Dump.java | 38 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/emm/src/main/java/whelk/Dump.java b/emm/src/main/java/whelk/Dump.java index 079b515835..96ae8c2d7e 100644 --- a/emm/src/main/java/whelk/Dump.java +++ b/emm/src/main/java/whelk/Dump.java @@ -206,6 +206,9 @@ private static void sendFormattedResponse(Whelk whelk, String apiBaseUrl, String Map idsAndRecords = whelk.bulkLoad(recordIdsOnPage); for (Document doc : idsAndRecords.values()) { + if (doc.getDeleted()) { + continue; + } // Here is a bit of SPECIALIZED treatment only for the itemAndInstance:categories. These should // include not only the Item (which is the root node for this category), but also the linked Instance. @@ -326,22 +329,23 @@ private static void generateDump(Whelk whelk, String dump, Path dumpFilePath) { } private static PreparedStatement getAllDumpStatement(Connection connection) throws SQLException { - String sql = " SELECT " + - " id" + - " FROM" + - " lddb"; + String sql = """ + SELECT id + FROM lddb + WHERE deleted = false + """; PreparedStatement preparedStatement = connection.prepareStatement(sql); return preparedStatement; } private static PreparedStatement getLibraryXDumpStatement(Connection connection, String library) throws SQLException { - String sql = " SELECT " + - " id" + - " FROM" + - " lddb" + - " WHERE" + - " collection = 'hold' AND" + - " (data#>>'{@graph,1,heldBy,@id}' = ? OR data#>>'{@graph,1,heldBy,@id}' = ?)"; + String sql = """ + SELECT id + FROM lddb + WHERE collection = 'hold' + AND (data#>>'{@graph,1,heldBy,@id}' = ? OR data#>>'{@graph,1,heldBy,@id}' = ?) + AND deleted = false + """; PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, Document.getBASE_URI().resolve("/library/"+library).toString()); @@ -359,12 +363,12 @@ private static PreparedStatement getTypeXDumpStatement(Connection connection, Wh Set types = whelk.getJsonld().getSubClasses(type); types.add(type); - String sql = " SELECT " + - " id" + - " FROM" + - " lddb" + - " WHERE" + - " data#>>'{@graph,1,@type}' = ANY( ? )"; + String sql = """ + SELECT id + FROM lddb + WHERE data#>>'{@graph,1,@type}' = ANY( ? ) + AND deleted = false + """; PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setArray(1, connection.createArrayOf("TEXT", types.toArray() ));