From cc7d095a1cf7b56cc3106fbdbbac178371a66164 Mon Sep 17 00:00:00 2001 From: Nicholas Jakobsen Date: Sat, 27 May 2023 20:00:05 -0700 Subject: [PATCH 1/2] Don't keep checking if migration is needed This has serious performance penalties when the imap file is large as the check is being run for each message imported. With a 20MB imap file (approximately 300,000) emails, it takes about 0.5 seconds to check the migration status on each message import. Instead, we remember that we have successfully validated and skip the check on subsequent calls to `validate!`. If validation fails, we allow the method to evaluate fully on subsequent calls. --- CHANGELOG.md | 7 +++++++ lib/imap/backup/serializer.rb | 8 +++++++- lib/imap/backup/version.rb | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19f3e2e7..13cb9c96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 9.3.2 - 2023-06-04 + +## Changed + +* Improved performance of large backups by avoiding unnecessary serialized + IMAP data migration and validation checks. + ## 9.3.1 - 2023-05-12 ## Changed diff --git a/lib/imap/backup/serializer.rb b/lib/imap/backup/serializer.rb index 642e418f..2aa777f7 100644 --- a/lib/imap/backup/serializer.rb +++ b/lib/imap/backup/serializer.rb @@ -30,14 +30,20 @@ class FolderIntegrityError < StandardError; end def initialize(path, folder) @path = path @folder = folder + @validated = nil end # Returns true if there are existing, valid files # false otherwise (in which case any existing files are deleted) def validate! + return if @validated + optionally_migrate2to3 - return true if imap.valid? && mbox.valid? + if imap.valid? && mbox.valid? + @validated = true + return true + end delete diff --git a/lib/imap/backup/version.rb b/lib/imap/backup/version.rb index 9badaaee..01138f04 100644 --- a/lib/imap/backup/version.rb +++ b/lib/imap/backup/version.rb @@ -3,7 +3,7 @@ module Imap; end module Imap::Backup MAJOR = 9 MINOR = 3 - REVISION = 1 + REVISION = 2 PRE = nil VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".") end From 2010d295feb3b50d4a6ce223b5c61fc22e03ffb5 Mon Sep 17 00:00:00 2001 From: Joe Yates Date: Sat, 8 Jul 2023 08:54:28 +0200 Subject: [PATCH 2/2] Add Rubocop fix --- .rubocop_todo.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fbbba084..2f7af282 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-06-30 17:40:25 UTC using RuboCop version 1.51.0. +# on 2023-07-08 06:54:16 UTC using RuboCop version 1.51.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -20,7 +20,7 @@ Metrics/BlockLength: # Offense count: 9 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 175 + Max: 180 # Offense count: 5 # Configuration parameters: AllowedMethods, AllowedPatterns.