Skip to content

Commit

Permalink
fix(emm): Don't include deleted docs in dump
Browse files Browse the repository at this point in the history
  • Loading branch information
olovy committed Nov 25, 2024
1 parent be8af49 commit 7c4158b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions emm/src/main/java/whelk/Dump.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ private static void sendFormattedResponse(Whelk whelk, String apiBaseUrl, String

Map<String, Document> 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.
Expand Down Expand Up @@ -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());
Expand All @@ -359,12 +363,12 @@ private static PreparedStatement getTypeXDumpStatement(Connection connection, Wh
Set<String> 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() ));
Expand Down

0 comments on commit 7c4158b

Please sign in to comment.