From 6e23d693e26e87a0e3331d466f27b072ebfb99be Mon Sep 17 00:00:00 2001 From: Brett Ryan Date: Tue, 1 Jul 2014 12:48:55 +1000 Subject: [PATCH] Versions are tested for size in newest first order. --- .../attachments/PurgeAttachmentsJob.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/drunkendev/confluence/plugins/attachments/PurgeAttachmentsJob.java b/src/main/java/com/drunkendev/confluence/plugins/attachments/PurgeAttachmentsJob.java index dca6996..8fd46a6 100644 --- a/src/main/java/com/drunkendev/confluence/plugins/attachments/PurgeAttachmentsJob.java +++ b/src/main/java/com/drunkendev/confluence/plugins/attachments/PurgeAttachmentsJob.java @@ -245,20 +245,15 @@ private int filterAge(List prior, int maxDaysOld) { } private int filterSize(List prior, long maxTotalSize) { - long fileSize = 0; long maxSizeKiB = maxTotalSize * 1024 * 1024; - - int m = -1; - - for (int i = 0; i < prior.size(); i++) { - fileSize += prior.get(i).getFileSize(); - if (fileSize > maxSizeKiB) { - m = i; - } else if (m > -1) { - break; + long total = 0; + for (int i = prior.size() - 1; i >= 0; i--) { + total += prior.get(i).getFileSize(); + if (total > maxSizeKiB) { + return i; } } - return m; + return -1; } private void mailResultsPlain(Map> mailEntries1) throws MailException { @@ -360,7 +355,7 @@ public int compare(MailLogEntry o1, MailLogEntry o2) { sb.append("

Started: ") .append(df.format(started)) - .append("EndedEnded: ") .append(df.format(ended)) .append("

");