use a nested sql statement for tstamp deletion

pull/53/head
Zlatin Balevsky 2020-10-22 10:40:39 +01:00
parent a795fec72c
commit 0e658d39a4
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 3 additions and 9 deletions

View File

@ -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