@@ -452,16 +452,15 @@ private void removeOldLastListUsed(Connection dbConn, Logger logger, CronProcess
452
452
//Remove old last list used
453
453
try {
454
454
//Get list of libraries that want last used list cleared
455
- PreparedStatement librariesListStmt = dbConn .prepareStatement ("SELECT libraryId, deleteOldLastListUsedEntries from library where deleteOldLastListUsedEntries > 0 " );
456
- PreparedStatement libraryLocationsStmt = dbConn .prepareStatement ("SELECT locationId from location where libraryId = ?" );
457
- PreparedStatement deleteLastListUsedStmt = dbConn .prepareStatement ("DELETE from user where lastListUsed = ?" );
455
+ PreparedStatement librariesListStmt = dbConn .prepareStatement ("SELECT libraryId FROM library WHERE deleteLastListUsedEntries = 1 " );
456
+ PreparedStatement libraryLocationsStmt = dbConn .prepareStatement ("SELECT locationId FROM location where libraryId = ?" );
457
+ PreparedStatement deleteLastListUsedStmt = dbConn .prepareStatement ("UPDATE user SET lastListUsed = NULL WHERE lastListUsed = ?" );
458
458
459
459
ResultSet librariesListRS = librariesListStmt .executeQuery ();
460
460
461
461
long numDeletions = 0 ;
462
462
while (librariesListRS .next ()) {
463
463
long libraryId = librariesListRS .getLong ("libraryId" );
464
- long daysToPreserve = librariesListRS .getLong ("deleteLastUsedListEntries" );
465
464
466
465
libraryLocationsStmt .setLong (1 , libraryId );
467
466
@@ -476,10 +475,10 @@ private void removeOldLastListUsed(Connection dbConn, Logger logger, CronProcess
476
475
}
477
476
if (libraryLocations .length () > 0 ) {
478
477
long now = new Date ().getTime () /1000 ;
478
+ long daysToPreserve = 14 ;
479
+ long earliestDateToPreserve = now - (daysToPreserve * 24 * 60 * 60 );
479
480
480
- long earliestDateToPreserve = now - (14 * 24 * 60 * 60 );
481
-
482
- PreparedStatement lastListUsedEntriesToDeleteStmt = dbConn .prepareStatement ("SELECT lastListUsed from user where user.homeLocationId IN (" + libraryLocations + ") and lastListused < ?" );
481
+ PreparedStatement lastListUsedEntriesToDeleteStmt = dbConn .prepareStatement ("SELECT lastListUsed FROM user WHERE user.homeLocationId IN (" + libraryLocations + ") AND lastListused < ?" );
483
482
lastListUsedEntriesToDeleteStmt .setLong (1 , earliestDateToPreserve );
484
483
485
484
ResultSet lastListUsedEntriesToDeleteRS = lastListUsedEntriesToDeleteStmt .executeQuery ();
@@ -495,6 +494,8 @@ private void removeOldLastListUsed(Connection dbConn, Logger logger, CronProcess
495
494
}
496
495
librariesListRS .close ();
497
496
librariesListStmt .close ();
497
+ libraryLocationsStmt .close ();
498
+ deleteLastListUsedStmt .close ();
498
499
processLog .addNote ("Removed " + numDeletions + " expired last list used entries" );
499
500
} catch (SQLException e ) {
500
501
processLog .incErrors ("Unable to remove expired last used list entries." , e );
0 commit comments