From 0e658d39a4f9432e51b02332ad0d1b46324a0138 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Thu, 22 Oct 2020 10:40:39 +0100 Subject: [PATCH] use a nested sql statement for tstamp deletion --- .../com/muwire/core/hostcache/H2HostCache.groovy | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy index 5aa2fa4c..cebbebe3 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy @@ -160,15 +160,9 @@ class H2HostCache extends HostCache { profiles.put(d, new HostMCProfile(newProfile)) log.fine("profile updated ${d.toBase32()} ${profiles.get(d)}") - def rows = sql.rows("select TSTAMP from HOST_ATTEMPTS where DESTINATION=${d.toBase64()} order by TSTAMP desc") - if (rows.size() <= settings.hostProfileHistory) - return - - def lastTstamp = rows[settings.hostProfileHistory - 1].TSTAMP - lastTstamp = SDF.format(new Date(lastTstamp.getTime())) - int limit = count.COUNT - settings.hostProfileHistory - sql.execute("delete from HOST_ATTEMPTS where DESTINATION=${d.toBase64()} and TSTAMP < $lastTstamp limit $limit") - log.fine("deleted $sql.updateCount old attempts older than $lastTstamp") + sql.execute("delete from HOST_ATTEMPTS where DESTINATION=${d.toBase64()} and TSTAMP not in "+ + "(select TSTAMP from HOST_ATTEMPTS where DESTINATION=${d.toBase64()} order by TSTAMP desc limit $settings.hostProfileHistory)") + log.fine("deleted $sql.updateCount old attempts") } @Override