Skip to content

Commit

Permalink
[EAT-101] Add metadataURL overwrite support
Browse files Browse the repository at this point in the history
v2.1.3
- Fixed bug with Cache database. The expired entries were not deleted because of DB FK relation violated, making location search slower and slower as people use the AtlasMapper.
  • Loading branch information
gaellafond committed Oct 21, 2020
1 parent 30d80ab commit 1794997
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<groupId>au.gov.aims</groupId>
<artifactId>atlasmapper</artifactId>
<packaging>war</packaging>
<version>2.1.2</version>
<version>2.1.3</version>
<name>AtlasMapper server and clients</name>
<description>This application compiled as a single War, that can be deployed in Tomcat, without any other dependency.\n\
It contains:\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public synchronized void delete(URL url) throws SQLException {
throw new IllegalArgumentException("URL is null.");
}

this.deleteCacheUsage(url.toString());

String deleteQuery = "DELETE FROM cache WHERE url = ?";

PreparedStatement deletePreparedStatement = null;
Expand Down Expand Up @@ -308,13 +310,34 @@ public synchronized void deleteExpired() throws SQLException {
throw new IllegalStateException("Database connection is closed.");
}

long now = CacheEntry.getCurrentTimestamp();

String deleteCacheUsageQuery = "DELETE FROM cacheUsage WHERE url IN " +
"(SELECT DISTINCT c.url FROM cache c WHERE expiryTimestamp < ?)";

PreparedStatement deleteCacheUsageStmt = null;
try {
deleteCacheUsageStmt = this.connection.prepareStatement(deleteCacheUsageQuery);
deleteCacheUsageStmt.setLong(1, now);
deleteCacheUsageStmt.executeUpdate();
} finally {
if (deleteCacheUsageStmt != null) {
try {
deleteCacheUsageStmt.close();
} catch(SQLException ex) {
LOGGER.log(Level.SEVERE, String.format("Can not close the delete expired cache usage statement: %s",
Utils.getExceptionMessage(ex)), ex);
}
}
}

String deleteQuery = "DELETE FROM cache " +
"WHERE expiryTimestamp < ?";

PreparedStatement deletePreparedStatement = null;
try {
deletePreparedStatement = this.connection.prepareStatement(deleteQuery);
deletePreparedStatement.setLong(1, CacheEntry.getCurrentTimestamp());
deletePreparedStatement.setLong(1, now);

deletePreparedStatement.executeUpdate();
} finally {
Expand Down Expand Up @@ -502,6 +525,26 @@ private void saveCacheUsage(URL url, Set<String> usage) throws SQLException {
}
}

private void deleteCacheUsage(String urlStr) throws SQLException {
String deleteCacheUsageQuery = "DELETE FROM cacheUsage WHERE url = ?";

PreparedStatement deleteCacheUsageStmt = null;
try {
deleteCacheUsageStmt = this.connection.prepareStatement(deleteCacheUsageQuery);
deleteCacheUsageStmt.setString(1, urlStr);
deleteCacheUsageStmt.executeUpdate();
} finally {
if (deleteCacheUsageStmt != null) {
try {
deleteCacheUsageStmt.close();
} catch(SQLException ex) {
LOGGER.log(Level.SEVERE, String.format("Can not close the delete cache usage statement: %s",
Utils.getExceptionMessage(ex)), ex);
}
}
}
}

private void deleteCacheUsage(String urlStr, String entityId) throws SQLException {
String deleteCacheUsageQuery = "DELETE FROM cacheUsage WHERE url = ? AND entityId = ?";

Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/admin/manualOverrideDoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
blockquote pre {
margin: 0;
}
pre {
white-space: pre-wrap;
}

#workflowDiv,
#settingsDiv,
Expand Down

0 comments on commit 1794997

Please sign in to comment.